我一直在尝试编写剧本,在其中我可以根据剧本运行的拱门(即 amd64、arm、ppc64le)运行不同的任务。我无法弄清楚如何获得正在运行它的系统的拱门。
你能帮我弄清楚 Ansible playbook 中的系统拱门吗?
最佳答案
获取系统架构
在命令行:
ansible HOST -m setup -a 'filter=ansible_architecture'
对于 x86 架构主机,这将返回:
HOST | SUCCESS => {
"ansible_facts": {
"ansible_architecture": "x86_64"
},
"changed": false
}
这是一个示例手册,它将打印出 list 中所有主机的体系结构:
- name: print out hosts architectures
hosts: all
gather_facts: True
tasks:
- debug: var= ansible_architecture
运行基于架构的任务
使用
when
条款:- name: task to run for x86 architecture
shell: echo "x86 arch found here"
when: ansible_architecture == "x86_64"
关于ansible - 如何根据 Ansible 剧本中的 arch 做出决策?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44713880/