我有select.yml
,其中包含IP和machine_id.yml
的提示,这些提示应包含在select.yml
中,并应成为select.yml
的主机。我尝试了许多配置,但均未成功。
如何重用machine_id.yml
并将主机注入其中?
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
答案 0 :(得分:1)
您的方法正确。 - import_playbook: machine_id.yml
必须处于- hosts:
以下是对我有用的示例:
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:
可以尝试一下吗?如果它不起作用,请告诉我们您的错误。