Ansible Cheat Sheet
Page content
Ansible Cheat Sheet
Facts
ansible host -m setup -i inventory.yaml
---
- hosts: spine,leaf
gather_facts: yes
connection: local
tasks:
# - name: Gather facts (eos)
# arista.eos.eos_facts:
# when: ansible_network_os == 'arista.eos.eos'
- name: Display some facts
debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
- name: get interface status
arista.eos.eos_command:
commands:
- command: show int status
when: ansible_net_version == "4.29.1F"
register: int_status
- name: Create backup dir
file:
path: "backup/{{ inventory_hostname }}"
state: directory
recurse: yes
- name: save interface status
local_action:
module: copy
content: "{{ int_status }}"
dest: backup/{{ inventory_hostname }}/{{ inventory_hostname }}.interface
- name: Backup switch (eos)
arista.eos.eos_config:
backup: yes
register: backup_eos_location
when: ansible_network_os == 'arista.eos.eos'
- name: Copy backup files into /tmp/backups/ (eos)
copy:
src: "{{ backup_eos_location.backup_path }}"
dest: "backup/{{ inventory_hostname }}/{{ inventory_hostname }}.bck"
when: ansible_network_os == 'arista.eos.eos'