Are all the tasks inside one playbook, or are different tasks in different jobs in an ansible tower workflow?
Use set_fact for within-playbook, and set_stats for creating artifacts sent back to ansible tower to be presented as extra_vars to downstream jobs in a workflow.
For within-playbook:
- set_fact:
admin_host: "{{ ansible_nodename }}"
For downstream jobs in a workflow:
- set_stats:
data:
admin_host: "{{ ansible_nodename }}"
If you need both you can do both. An artifact created with set_stats in a playbook cannot be used later in that same playbook as a variable. You have to use set_fact for that.
For loading your file within the playbook or downstream
- name: Set authorized key took from file
become: yes
authorized_key:
user: root
state: present
key: "{{ lookup('file', '/git/cephprep/files/' + admin_host + '/root/.ssh/id_rsa.pub') }}"
NOTE that I broke up the file path and inserted the admin_host with "+" which in Python (ansible runs on Python) will concatenate strings.
--
Walter Rowe, Chief
Infrastructure Service
Office of Information Systems Management
National Institute of Standards and Technology
US Dept of Commerce