Open djboni opened 2 years ago
Note that the return value from
lookup('ansible.builtin.password', '/dev/null', length=4, chars='hexdigits')
has type
ansible.utils.unsafe_proxy.AnsibleUnsafeText
.
Hi @djboni,
Thanks for opening this issue.
Can you show what's the result of you lookup in clear text ?
In the examples of the module ansible.builtin.password, I see similar cases, like yours, with different syntax. For example:
lookup('ansible.builtin.password', '/dev/null chars=ascii_lowercase,digits length=8'
Could you please try your playbook with the syntax above? In your case, that would be:
lookup('ansible.builtin.password', '/dev/null length=4 chars=hexdigits')
Hi, I tried the code below (old and suggested lookups):
---
- name: Not creating user with random password from variable
hosts: test-ubuntu
vars:
mariadb_user_password1: "{{ lookup('ansible.builtin.password', '/dev/null', length=4, chars='hexdigits') }}"
mariadb_user_password2: "{{ lookup('ansible.builtin.password', '/dev/null length=4 chars=hexdigits') }}"
tasks:
- name: Lookup 1
debug:
msg: "Lookup 1: mariadb_user_password1={{ mariadb_user_password1 }} type={{ mariadb_user_password1 | type_debug }}."
- name: Lookup 2
debug:
msg: "Lookup 2: mariadb_user_password2={{ mariadb_user_password2 }} type={{ mariadb_user_password2 | type_debug }}."
The output is:
TASK [Lookup 1] ************************************************************************************************************
ok: [test-ubuntu] => {
"msg": "Lookup 1: mariadb_user_password1=F2Ae type=AnsibleUnsafeText."
}
TASK [Lookup 2] ************************************************************************************************************
ok: [test-ubuntu] => {
"msg": "Lookup 2: mariadb_user_password2=2efD type=AnsibleUnsafeText."
}
After reading Ansible documentation about unsafe text, it seems normal and recommended to use that for passwords.
Did you check if users where created correctly in users table, with a password set and for the right host?
Yes the users are created:
# echo "select user,host,password from user;" | mysql -u root mysql
User Host Password
mariadb.sys localhost
root localhost invalid
mysql localhost invalid
database_user1 localhost *DF1434D536015CFB52BF62D468EE416167FCCC1C
database_user2 localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
Thanks for the details.
Did you try to connect to the server directly with MySQL client and the created credentials?
Could you add a flush privileges play before restarting the server?
SUMMARY
Cannot create user with random password from variable
ISSUE TYPE
COMPONENT NAME
mysql_user
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Host: Ubuntu 22.04 Targets: Ubuntu 22.04, Debian 11
STEPS TO REPRODUCE
See playbook below:
EXPECTED RESULTS
I expect to be able to login with both database_user1 and database_user2.
ACTUAL RESULTS
Cannot login with database_user1. Can login with database_user2.