Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in Ansible’s inventory, which defaults to being saved in the location /etc/ansible/hosts. You can specify a different inventory file using the -i <path> option on the command line.

To ingore RSA key fingerprint concerns:

  1. Setting the environment variable ANSIBLE_HOST_KEY_CHECKING to False.
  2. Put it in an ansible.cfg file, either set that globally (at system or user level, in /etc/ansible/ansible.cfg or ~/.ansible.cfg), or in an config file(ansible.cfg) in the same directory as the playbook you are running.

How to retry

Example Adding only retries will not work, it has to work with until togther:

- hosts: all
  connection: local
      - shell: exit 1
        register: task_result
        until: task_result.rc == 0
        retries: 10
        delay: 1
        ignore_errors: yes

Script Sample Explaination

To create a backup of a given nxos switch, host file example hosts.yml:



N7004L host=
N7004R host=


ansible-playbook can be backup.yml:

- hosts: cisco
  connection: local
  gather_facts: no
      host: "{{ host }}"
      username: "{{ username }}"
      password: "{{ password }}"
  - name: create a backup
      backup: yes
      provider: "{{provider}}"

where host is a must, or it gives error fatal: [N7004R]: FAILED! => {"msg": "[Errno -2] Name or service not known"}. The {{ host }} here actually refers to hosts defined in playbook cmd ansible-playbook -i hosts backup.yml mixed with hosts:cisco in backup.yml. this will create a backup folder with switch show run output under current folder. so if we have multiple vdcs and want to backup all of them, what should I do? nxos_command will be your best friend.

- name: Save Configurations (NXOS)
  hosts: cisco
      host: "{{ host }}"
      username: "{{ username }}"
      password: "{{ password }}"
    - ios_command:
        provider: "{{ creds }}"
        commands: show run vdc-all
      register: show_run                   #mark show_run as var to be used later
    - name: Ensures conf dir exists
        path: conf                         #create folder conf if not exists
        state: directory
    - copy:
        content: "{{ show_run.stdout[0] }}"
        dest: "conf/{{ inventory_hostname }}.txt"   #recall show_run output and copy to conf folder
    - debug:
        msg: "{{ show_run }}"             #this is not necessary, it's just for debug