ansible - 运行剧本,将主机作为参数传递,但主机不作为 /ansible/hosts 中的条目存在
问题描述
为什么在运行剧本时将主机名作为参数传递,而 /ansible/host 文件中不存在该主机名?
我确实尝试过
ansible-playbook -i 主机名,playook.yml
解决方案
确保您的主机是剧本中的全部或变量:
---
- name: Test
hosts: all
gather_facts: True
tasks:
- name: Debug
debug:
var: groups
然后运行为:
ansible-playbook --inventory=windows, debug.yml
你会得到:
PLAY [Test] **************************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************
ok: [windows]
TASK [Debug] *************************************************************************************************************************************************************
ok: [windows] => {
"groups": {
"all": [
"windows"
],
"ungrouped": [
"windows"
]
}
}
PLAY RECAP ***************************************************************************************************************************************************************
windows : ok=2 changed=0 unreachable=0 failed=0
其他选项是使用变量并在运行时传递它:
所以:
---
- name: Test
hosts: "{{ host }}"
gather_facts: True
tasks:
- name: Debug
debug:
var: groups
并做:
ansible-playbook debug.yml -e host=windows
除此之外,您还有add_host
或group_by
选项
推荐阅读
- c - C 中的 Sscanf - 从 .txt 中读取数字。文件
- javascript - 将excel转换为json数组时无法解析日期
- python - 如何使用 tf.data 创建图像序列样本?
- android - 如果应用程序在主线程中运行,为什么服务不会阻止应用程序?
- json - React Native - 根据 FlatList 中的另一个 const JSON 过滤 JSON
- android - Android MediaPlayerNative:来自 url 的错误(1,-2147483648)音频
- reactjs - 自定义安全区域视图底部填充的颜色/内容
- python - 仅解析具有多列的 CSV 文件的列
- javascript - 通过 javascript 以 HTML Thymeleaf 形式发送 HashMap 密钥
- winrt-xaml - 如何注册应与值类型一起使用的 DependencyProperty