首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重用攻略并传递主攻略中的主机

重用攻略并传递主攻略中的主机
EN

Stack Overflow用户
提问于 2020-08-29 22:43:39
回答 1查看 31关注 0票数 1

我有select.yml的IP和machine_id.yml的提示符,这应该包括从select.yml,并应该从select.yml主机。我尝试了许多配置,但都没有成功。

如何重用machine_id.yml并向其中注入主机?

select.yml

代码语言:javascript
复制
- 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

代码语言:javascript
复制
- 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-30 00:01:55

你走在正确的道路上。- import_playbook: machine_id.yml必须在- hosts:级别

下面是一个适用于我的示例:

select.yaml:

代码语言:javascript
复制
- 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:

代码语言:javascript
复制
- hosts: dynamic_hosts
  gather_facts: no
  tasks:
    - ping:

你能试一试吗?如果它不工作,请让我们知道你的错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63648231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档