I have been trying to write playbooks where I can run different tasks based on the arch (i.e amd64, arm, ppc64le) that the playbook is running on. I am not able to figure out how do I get the arch of the system I am running it on.
Can you please help me with figuring out the arch of the system in Ansible playbook.
At the command line:
ansible HOST -m setup -a 'filter=ansible_architecture'
For an x86 architecture host, this would return:
HOST | SUCCESS => {
"ansible_facts": {
"ansible_architecture": "x86_64"
},
"changed": false
}
Here’s a sample playbook that will print out the architecture of all hosts in your inventory:
- name: print out hosts architectures
hosts: all
gather_facts: True
tasks:
- debug: var= ansible_architecture
Use a when
clause:
- name: task to run for x86 architecture
shell: echo "x86 arch found here"
when: ansible_architecture == "x86_64"
@Pensu it's maybe what you're looking for:
- name: Get DEB architecture
shell: dpkg --print-architecture
register: deb_architecture
- name: Print DEB architecture
debug:
msg: "deb_architecture.stdout: {{ deb_architecture.stdout }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With