Ansible 2.1.0 - How to avoid dashes error with rendering templates (like my.cnf)

Hi all!

I am new in Ansible and this Group, so thanks in advance for the patience and help.

I’m writing a Playbook Roles for install and setup MySQL RDBMS on Linux (CentOS), and I get an error with the template module when ansible parses the my.cnf.j2.
Here the msg err

TASK [mysql : Copy my.cnf global MySQL configuration.] *************************
task path: /opt/settings/ansible/roles/mysql/tasks/configure.yml:2
fatal: [v1080udesa]: FAILED! => {“changed”: false, “failed”: true, “invocation”: {“module_args”: {“dest”: “/etc/my.cnf”, “group”: “root”, “mode”: “0644”, “owner”: “root”, “src”: “my.cnf.j2”}, “module_name”: “template”}, “msg”: “AnsibleUndefinedVariable: Unable to look up a name or access an attribute in template string (# The MySQL database server configuration file.\n [ cut output for sanity ] key_buffer\t\t\t= 64M\n\n).\nMake sure your variable name does not contain invalid characters like ‘-’: unsupported operand type(s) for -: ‘StrictUndefined’ and ‘StrictUndefined’”}
to retry, use: --limit @install_mysql.retry

PLAY RECAP *********************************************************************

I’m refurbishing one Role from Ansible-Galaxy, so I think that this works already for others DBAs. (but i don’t know if this version work)
I searched several roles on Galaxy and all users have the same template command and similar template file.
In addition, I leave the link: https://galaxy.ansible.com/geerlingguy/mysql/
Could someone help me to find if it is an error with the playbook or a version bug?

Regards!

Hi again, I found the problem.
I did not realize from change the name of the values in template and I only changed it in the defaults file.

myisam-recover-options = {{ mysql_myisam-recover-options }}

So, I correct it and it works.

Thanks!

I was also having the same error,

I was substituting the variable like this {{var_property1-role}} ,

ansible doesn’t permit - in variable names so by changing

{{var_property1-role}} to {{var_property1_role}} it worked fine.

Your post was of great help.

Thanks,
Sukhdeep

This is how we solved it:

https://github.com/Oefenweb/ansible-percona-server