Reputation: 1874
I have select.yml
with prompts for IP and machine_id.yml
which should be included from select.yml
and should takes host from select.yml
. I've tried many configurations without success.
How to reuse machine_id.yml
and inject host into it?
select.yml
- hosts: localhost
gather_facts: no
vars_prompt:
- name: target_host
prompt: "[M] please enter the target host IP"
private: no
tasks:
- add_host:
name: "{{ target_host }}"
groups: dynamic_hosts
- import_playbook: machine_id.yml
machine_id.yml
- hosts: localhost
gather_facts: no
vars_prompt:
- name: target_host
prompt: please enter the target host IP
private: no
tasks:
- add_host:
name: "{{ target_host }}"
groups: dynamic_hosts
- hosts: "{{ dynamic_hosts }}"
vars:
ansible_python_interpreter: /usr/bin/python3
become: yes
tasks:
- name: Reset machine-id
shell: rm /etc/machine-id && rm /var/lib/dbus/machine-id && dbus-uuidgen --ensure=/etc/machine-id && dbus-uuidgen --ensure
args:
warn: no
Upvotes: 1
Views: 112
Reputation: 1457
You were on the right way. - import_playbook: machine_id.yml
must be on the level of - hosts:
Here is an example which worked for me:
select.yaml:
- hosts: localhost
gather_facts: no
vars_prompt:
- name: target_host
prompt: "[M] please enter the target host IP"
private: no
tasks:
- add_host:
name: "{{ target_host }}"
groups: dynamic_hosts
- debug: var=groups
- import_playbook: machine_id.yaml
machine_id.yaml:
- hosts: dynamic_hosts
gather_facts: no
tasks:
- ping:
Can you give it a try? If it's not working, please let us know your error.
Upvotes: 1