The playbook I am developping should run after authentication on a single host (hostA) specified in command line with parameter (--extra-vars) eg: [ansible-playbook main.yaml -e "variable_host=hostA"]
This main playbook includes a part1 and a part2 and it is expected that the hostA will disconnect the ansible session due to a reboot between part1 and part2.
Two solutions have been unsuccesfully tried:
First solution: (with include_tasks for each part: The first part1 is successfully processed on hostA, but the second part2 fails. This is due to a connection issue, because the part2 expects user/pwd. The vars_prompt seems to only be available for the part1 only)
main.yaml
hosts: "{{ variable_host | default('All-host')}}"
vars_prompt:
- name: ADMUSER
prompt: Username
private: no
- name: ADMPASS
prompt: password
private: yes
tasks:
- name: ==> Part1
include_tasks: TEST1.yaml
- name: ==> Part2
include_tasks: TEST2.yaml
Second solution: (with import_playbook for each part: First part1 is successfully processed. The second connection to the part2 is successful, but the part2 runs on all the hosts. The part2 should only run on hostA. The host variables is not overriden by --extra-vars)
main.yaml
- import_playbook: playbook1.yaml
- import_playbook: playbook2.yaml
playbook1.yaml
hosts: "{{ variable_host | default('All-host')}}"
vars_prompt:
- name: ADMUSER
prompt: Username
private: no
- name: ADMPASS
prompt: password
private: yes
tasks:
- nameA1:xxxx
- nameB1:xxxx
playbook2.yaml
hosts: "{{ variable_host | default('All-host')}}"
vars_prompt:
- name: ADMUSER
prompt: Username
private: no
- name: ADMPASS
prompt: password
private: yes
tasks:
- nameA2:xxxx
- nameB2:xxxx
So, is there a solution to maintain the --extra-vars for hostA for part1 and part2 even if a disconnection occurs? Note I am not in favor of a solution which modifies the config file "hosts" to restrict the playbook to a single host. Thanks Richard