I'm using Ansible 2.3.0 and writing a playbook that creates MySQL users 
based on a list of user.

My playbook tree:

|--inventories
|  |--staging
|  |  |--hosts
|--roles
|  |--create_mysql_users
|  |  |--tasks
|  |  |  |--main.yml
|  |  |--vars
|  |  |  |--mysql_users.yml
|--site.yml

site.yml 

- hosts: mysql
  remote_user: centos
  become: yes
  become_method: sudo
  roles:
  - create_mysql_users

roles/create_mysql_users/tasks/main.yml 

---
- include_vars: 
    file="mysql_users.yml" 
    name="mysql_users"

- name: Create MySQL account
  mysql_user:
    name: "{{ item.username }}"
    password: "{{ item.password }}"
    host_all: "{{ item.host_all }}"
    priv: "{{ item.priv }}"
  with_items: "{{ mysql_users }}"


roles/create_mysql_users/vars/mysql_users.yml

---
user1: { username: user1, password: secret, host: "%", priv: 
"*.*:ALL,GRANT", state: present }

When executing playbook I got error:

# ansible-playbook site.yml -i inventories/stg/hosts -l mysql -C -vv

<snip>
TASK [mysql_create_users : include_vars] 
*******************************************************************************
task path: /root/ansible-playbook/roles/create_mysql_users/tasks/main.yml:2
ok: [IP_ADDR] => {"ansible_facts": {"mysql_users": {"user1": {"host": "%", 
"password": "secret", "priv": "*.*:ALL,GRANT", "state": "present", 
"username": "user1"}}}, "changed": false}

TASK [mysql_create_users : debug] 
**************************************************************************************
task path: /root/ansible-playbook/roles/create_mysql_users/tasks/main.yml:5
ok: [IP_ADDR] => {
    "changed": false,
    "mysql_users": {
        "user1": {
            "host": "%",
            "password": "secret",
            "priv": "*.*:ALL,GRANT",
            "state": "present",
            "username": "user1"
        }
    }
}

TASK [mysql_create_users : Create or Remove MySQL account] 
*************************************************************
task path: /root/ansible-playbook/roles/create_mysql_users/tasks/main.yml:7
fatal: [IP_ADDR]: FAILED! => {"failed": true, "msg": "the field 'args' has 
an invalid value, which appears to include a variable that is undefined. 
The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no 
attribute 'password'\n\nThe error appears to have been in 
'/root/ansible-playbook/roles/create_mysql_users/tasks/main.yml': line 7, 
column 3, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n- name: Create or Remove 
MySQL account\n  ^ here\n"}

I don't understand the error message, can anybody help me figure out what's 
wrong in my playbook please? 
Appreciate

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/eb799d08-935b-4380-9950-367492b3a5e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to