I find it easy to describe what I want to do showing how I tried to implement it, as below.
In one playbook1.yml, I have:
- name: set facts with ssh connecton details
set_fact:
ssh_user: "user01"
ssh_pass: "passw0rd"
In my playbook2.yml, I want to do something similar to this:
import_playbook: playbook1.yml
Vars:
ansible_user: "{{ ssh_user }}"
ansible_ssh_pass: "{{ ssh_pass }}"
After this, my tasks in the playbook2.yml should attempt to use sshpass when connecting to my remote hosts, getting user and pass for the "ansible_*" Vars above.
Can be done? Clearly that is not working and I am unable to find a solution for this.
Setting Ansible facts for the ssh Vars does work - clearly it needs Vars to trigger sshpass and use password for remote access.
I know ssh keys is the way to go, and that is being covered, however I also need a solution for this specific use case.
Thanks in advance for any help.
question from:https://stackoverflow.com/questions/65925981/is-it-possible-to-set-ansible-vars-from-existing-facts