-1

I'm new to all the Ansible stuff. So most of the time I'm in "Trial and Error"-Mode.

Now I'm facing a challenge with a playbook and I do not know to look further.

The main task of this playbook should be to get a "Show run" from a Cisco Device and save this in a text file on a backup server (which is a remote server).

The only task, which is not working, is the Backup Task.

Here is my playbook:

- hosts: IOSGATEWAY
  gather_facts: no
  connection: local
  tasks:
  - name: GET CREDENTIALS
    include_vars: path/to/all/all.yml

  - name: DEFINE CONNECTION TO GW
    set_fact:
       connection:
          host: "{{ inventory_hostname }}"
          username: "{{ creds['username'] }}"
          password: "{{ creds['password'] }}"

  - name: GET SHOW RUN 
    ios_command:
      provider: "{{ connection }}"
      commands:
         - show run
    register: show_run

  - name: SAVE TO BACKUP SERVER
    copy:
      content: "{{ show_run.stdout[0] }}"
      dest: "path/to/Directory/{{ inventory_hostname }}.txt"
    delegate_to: BACKUPSERVER

Can someone hint me in the right direction?

Paulw11
  • 108,386
  • 14
  • 159
  • 186
DrMxxxxx
  • 15
  • 1
  • 9

1 Answers1

1

You set connection: local for the playbook, so everything you do is executed locally (which is correct for ios_... modules, but not what you actually want for copy module).

I'd recommend to define ansible_connection variable in your inventory per group of hosts/devices, so Ansible will use local connection for your ios devices, and ssh for backup-server.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193