Dear all,
After re-organising my playbooks using roles and changing $PASSWORD(credentials/mysql/root) to {{ lookup(‘password’, ‘credentials/mysql/root’) }}, I run into troubles configuring mysql.
file: ansible-playbooks/roles/mysql/tasks/main.yml
-
name: MySQL | Set the root password
mysql_user: user=root password=“{{ lookup(‘password’, ‘credentials/mysql/root’) }}” host=localhost -
name: MySQL | Config for easy access as root user
template: src=root-my-cnf.j2 dest=/root/.my.cnf
file: ansible-playbooks/roles/mysql/templates/root-my-cnf.j2
[client]
user=root
pass={{ lookup(‘password’, ‘credentials/mysql/root’) }}
I didn’t expect any change after the reorganization, but although both mysql_user and template action use the same lookup, they access different files:
- template: as expected, ansible-playbooks/credentials/mysql/root and uses old password
- mysql_user: ansible-playbooks/roles/mysql/files/credentials/mysql/root and generates new (and different) password
Note that ansible-playbooks/roles/mysql/files exists and contains other files, but credentials didn’t exist before running the playbook.
Quick and dirty workarounds would be to rely on either (obsolete) $PASSWORD-syntax, or create symlinks roles/mysql/files/credentials to …/…/…/credentials, or use absolute paths. None of these solutions seem elegant, so I’m looking for a proper solution.
Any ideas how to make sure the top-level credentials files is accessed by both mysql_user and template actions?
Kind regards,
Koen