# Unexpected password-lookup behaviour after re-organizing playbooks using roles

**URL:** <https://forum.ansible.com/t/unexpected-password-lookup-behaviour-after-re-organizing-playbooks-using-roles/13988>\
**Category:** Ansible Project\
**Created:** [November 24, 2013, 9:17am UTC](https://forum.ansible.com/t/unexpected-password-lookup-behaviour-after-re-organizing-playbooks-using-roles/13988 "2013-11-24T09:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koen\_Smets](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Koen\_Smets](https://forum.ansible.com/u/Koen_Smets)\
**Post date:** [November 24, 2013, 9:17am UTC](https://forum.ansible.com/t/unexpected-password-lookup-behaviour-after-re-organizing-playbooks-using-roles/13988/1 "2013-11-24T09:17:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 24, 2013, 4:03pm UTC](https://forum.ansible.com/t/unexpected-password-lookup-behaviour-after-re-organizing-playbooks-using-roles/13988/2 "2013-11-24T16:03:56Z")

</div>

The plugin will not generate password files when they are present.

I suspect you were running the playbook when the file was not present and it regenerated the password.

This is not a syntax issue.

---

<div class="post-metadata">

**Author:** ![Koen\_Smets](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Koen\_Smets](https://forum.ansible.com/u/Koen_Smets)\
**Post date:** [November 25, 2013, 8:14am UTC](https://forum.ansible.com/t/unexpected-password-lookup-behaviour-after-re-organizing-playbooks-using-roles/13988/3 "2013-11-25T08:14:19Z")

</div>

Let me clarify the issue:

The file /etc/ansible/credentials/mysql/root exists before running the playbook and the password therein is used by the template action (which is run after the mysql\_user action). However, for the mysql\_user a new file and password generated in /etc/ansible/roles/mysql/files/credentials/mysql/root.

I expected both mysql\_user and template action to access the same file (/etc/ansible/credentials/mysql/root).

Any ideas?

grtz, Koen
