My playbook:
---
- name: Playbook to create users
hosts: all
become: true
vars_files:
- /home/devops/become_pass.yml
- /home/devops/user_secret.yml
vars:
- ansible_become_password: "{{ become_pass }}"
tasks:
- name: User creation is in progress
user:
name: test321
comment: "Test user"
password: "{{ user_secret | password_hash('sha512', 'mysecretsalt') }}"
state: present
- name: Trying remote connectivity with newly created user
become: false
remote_user: test
vars:
ansible_ssh_pass: "{{ user_secret }}"
command:
cmd: id
register: x
no_log: true
- name: Connectivity result
debug:
msg: "User created successfully and remote connectivity with password was successful"
when: x.rc==0
...
Here I am using vault to pass become password and password to be set for user..
User creation is successful and its picking up password from my encrypted variable..
I have tested connectivity for this user with password.. its successful..
But, I am not able to achieve same from playbook.
I guess - ansible_ssh_pass: "{{ user_secret }}" one is causing issue..
how I can ask playbook to pickup ssh password for user from encrypted variable?