ansible - 重用剧本并从主剧本传递主机
问题描述
我有select.yml
IP 提示,machine_id.yml
它应该包含在select.yml
并且应该从select.yml
. 我尝试了很多配置都没有成功。
如何重用machine_id.yml
和注入主机?
选择.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
解决方案
你走对了。- import_playbook: machine_id.yml
必须在水平- hosts:
这是一个对我有用的例子:
选择.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:
你能试一试吗?如果它不起作用,请告诉我们您的错误。
推荐阅读
- sql - 查询所有表以检索所有列名和数据类型
- reactjs - 来自 React-Router-Dom 的低级路由器仅导航到新 URL,但不渲染组件
- python - 如何用python处理json中的无效转义序列?
- html - 我们可以在同一个 SVG 中使用两个“use: href”属性吗?
- clojure - 在 Clojure 中修剪 URL 的最后一部分
- rust - 是否可以丢弃解析失败的项目,继续用serde_json解析?
- python - 视觉 API 产品搜索
- python - 没有验证的最大值数据输入Python tkinter
- batch-file - 在一台特定 PC 上以管理员身份运行时,返回 Firefox 版本的 Cmd 失败
- android - react native开发的应用有哪些更新应用解决方案?