ansible - 如何根据 Ansible 剧本中的 arch 做出决策?

标签 ansible

我一直在尝试编写剧本,在其中我可以根据剧本运行的拱门(即 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/

相关文章:

python - Jinja 将字符串转换为整数

ansible - 错误! 'file' 不是 Play 的有效属性

amazon-web-services - 加速 AMI 和 ASG 创建

linux - Shell如何杀死一个进程并返回0

ansible - 如何区分暂存/生产与动态库存?

ansible - Ansible 中是否有列出群组的选项?

amazon-web-services - Ansible 与 AWS 内部函数 Fn::Cidr 有什么类比吗?

docker - 使用Ansible来配置Docker容器

windows - Ansible无法通过SSH连接到Windows节点

ansible - 整个剧本仅运行一次Ansible处理程序