bennojoy / mysql

ansible role for mysql
150 stars 137 forks source link

One or more undefined variables: 'str object' has no attribute 'name'", 'failed': True} for Copy my.cnf task #10

Closed kevinold closed 10 years ago

kevinold commented 10 years ago

I keep receiving the following error for the Copy my.cnf file task:

This output is with the -v flag, but I'm still not sure what the issue is.

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [192.241.139.34]

TASK: [mysql | Add the OS specific variables] ********************************* 
ok: [192.241.139.34] => {"ansible_facts": {"mysql_conf_dir": "/etc/mysql/", "mysql_pkgs": ["python-selinux", "mysql-server", "python-mysqldb"], "mysql_service": "mysql"}, "item": ""}

TASK: [mysql | Install the mysql packages in Redhat derivatives] ************** 
skipping: [192.241.139.34]

TASK: [mysql | Install the mysql packages in Debian derivatives] ************** 
ok: [192.241.139.34] => (item=python-selinux,mysql-server,python-mysqldb) => {"changed": false, "item": "python-selinux,mysql-server,python-mysqldb"}

TASK: [mysql | Copy the my.cnf file] ****************************************** 
fatal: [192.241.139.34] => {'msg': "One or more undefined variables: 'str object' has no attribute 'name'", 'failed': True}
fatal: [192.241.139.34] => {'msg': "One or more undefined variables: 'str object' has no attribute 'name'", 'failed': True}

FATAL: all hosts have already failed -- aborting
kevinold commented 10 years ago

Disregard it seems my mysql_db config wasn't an array. Closing.

anonymuse commented 10 years ago

I'm having the same problem, except that I'm not able to use "none" for the mysql_db as in the example.

- hosts: all
    roles:
    - {role: mysql, root_db_pass: foobar, mysql_db: none, mysql_users: none }

The my.cnf.RedHat.j2 here https://github.com/bennojoy/mysql/blob/master/templates/my.cnf.RedHat.j2 seems not to be able to handle "none" as input:

{% for i in mysql_db %}
{% if i.replicate|default(1) %}
binlog_do_db            = {{ i.name }}
{% endif %}
{% endfor %}

Error output:

TASK: [mysql | Copy the my.cnf file] ****************************************** 
fatal: [dev-database-03-jt] => {'msg': "One or more undefined variables: 'str object' has no attribute 'name'", 'failed': True}
fatal: [dev-database-03-jt] => {'msg': "One or more undefined variables: 'str object' has no attribute 'name'", 'failed': True}

FATAL: all hosts have already failed -- aborting

This works if I put in a single database:

  - {role: mysql, mysql_root_db_pass: 99d2dfdv, mysql_db: [name: ansible_DB], mysql_users: none }
damko commented 10 years ago

Instead of "none" use "[]"

- {
    role: bennojoy.mysql,
        mysql_root_db_pass: password,
        mysql_db: [],
        mysql_users: [],
        mysql_repl_user: []
}