# Network devices backup -cisco/dell

**URL:** <https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540>\
**Category:** Get Help\
**Created:** [March 25, 2024, 7:42am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540 "2024-03-25T07:42:30Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 25, 2024, 7:42am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/1 "2024-03-25T07:42:30Z")

</div>

Hello Team,  
below is my playbook ;

- name: AUTOMATIC BACKUP OF RUNNING-CONFIG  
hosts: Core\_Switch  
gather\_facts: true  
connection: local

But when i run it i get this error;  
FAILED! =\> {“changed”: false, “msg”: “Connection type local is not valid for this module”}

What could I be doing wrong?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 25, 2024, 4:21pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/2 "2024-03-25T16:21:20Z")

</div>

You cannot use both `connection: local` and `local_action:` at the same time. Not to mention that `local_action:` is deprecated in favor of `delegate_to: localhost` (which is more or less the same thing). Since all of these steps are running on the localhost, we can use `connection: local` as a default, and not redundantly delegate tasks to local when they already are.

For e.g:

```yaml
- name: AUTOMATIC BACKUP OF RUNNING-CONFIG
  hosts: Core_Switch
  gather_facts: false
  connection: local

  tasks:
    - name: DISPLAYING THE RUNNING-CONFIG
      ios_command:
        commands:
          - show run
        timeout: 30
        host: “{{ ansible_host }}”
        username: xxxxx
        password: yyyyy
      register: config

    - name: Get Current Date
      command:
        cmd: date +%Y-%b-%d
      register: date

    - name: Get Current Time
      command:
        cmd: date +%H:%M
      register: time

    - name: Save Output to /home/user1/Backups
      copy:
        content: “{{ config.stdout[0] }}”
        dest: “/home/user1/Backups/_{{ date.stdout }}at{{ time.stdout }}-{{ inventory_hostname }}.txt”

```

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 26, 2024, 9:48am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/3 "2024-03-26T09:48:15Z")

</div>

FAILED! =\> {“changed”: false, “msg”: “Connection type ssh is not valid for this module”}

Getting above error.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 26, 2024, 1:16pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/4 "2024-03-26T13:16:44Z")

</div>

Silly me, I left out `connection: local` at the top.

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 26, 2024, 1:56pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/5 "2024-03-26T13:56:14Z")

</div>

FAILED! =\> {“changed”: false, “msg”: “Connection type local is not valid for this module”}

Now getting this error:  
am on ansible 2.14.9

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 26, 2024, 1:58pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/6 "2024-03-26T13:58:25Z")

</div>

Which task is giving you that error? I didn’t think local connections were unsupported anywhere.

Edit:

Regardless, you could try delegation instead of setting the connection type.

```yaml
- name: AUTOMATIC BACKUP OF RUNNING-CONFIG
  hosts: Core_Switch
  gather_facts: false

  tasks:
    - name: DISPLAYING THE RUNNING-CONFIG
      ios_command:
        commands:
          - show run
        timeout: 30
        host: “{{ ansible_host }}”
        username: xxxxx
        password: yyyyy
      register: config
      delegate_to: localhost

    - name: Get Current Date
      command:
        cmd: date +%Y-%b-%d
      register: date
      delegate_to: localhost

    - name: Get Current Time
      command:
        cmd: date +%H:%M
      register: time
      delegate_to: localhost

    - name: Save Output to /home/user1/Backups
      copy:
        content: “{{ config.stdout[0] }}”
        dest: “/home/user1/Backups/_{{ date.stdout }}at{{ time.stdout }}-{{ inventory_hostname }}.txt”
      delegate_to: localhost

```

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 26, 2024, 2:13pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/7 "2024-03-26T14:13:29Z")

</div>

its now trying to ssh using root user of the linux.  
How can i make it use local?

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 26, 2024, 2:14pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/8 "2024-03-26T14:14:20Z")

</div>

i mean credentials defined on the playbook?

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 26, 2024, 2:37pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/9 "2024-03-26T14:37:47Z")

</div>

What does your inventory look like? Delegating to localhost should definitely be using connection local, not your ssh connection or credentials…

Wait wait. I’m looking at the [cisco.ios.ios\_command](https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_command_module.html) module now, and there’s no host/username/password parameter for that. There are modules that do, and expect to be run as connection local while it establishes its own connection to the host separately, but that doesn’t appear to be the case here.

Unless you specified the username/password for your ios hosts in inventory, I would expect you to need to do something like this:  
`ansible-playbook ./this_play.yml -u <ios_username> -k` # enter password for \<ios\_username\>

And the ios\_command module would pick up the credentials you’re using for the ios hosts, while the delegate\_to tasks will just use your local “user1” permissions.

```yaml
- name: AUTOMATIC BACKUP OF RUNNING-CONFIG
  hosts: Core_Switch
  gather_facts: false

  tasks:
    - name: DISPLAYING THE RUNNING-CONFIG
      ios_command:
        commands:
          - show run
      register: config

    - name: Get Current Date
      command:
        cmd: date +%Y-%b-%d
      register: date
      delegate_to: localhost

    - name: Get Current Time
      command:
        cmd: date +%H:%M
      register: time
      delegate_to: localhost

    - name: Save Output to /home/user1/Backups
      copy:
        content: “{{ config.stdout[0] }}”
        dest: “/home/user1/Backups/_{{ date.stdout }}at{{ time.stdout }}-{{ inventory_hostname }}.txt”
      delegate_to: localhost

```

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [March 27, 2024, 8:45am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/10 "2024-03-27T08:45:50Z")

</div>

> [@Denney-tech](#):
>
> n inventor

Have configured creds on hosts config file.  
Am i doing it wrong?  
but still complain about module local not supported.  
funny enough the same was running well on cent os, till i moved to rocky linux.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 27, 2024, 2:10pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/11 "2024-03-27T14:10:22Z")

</div>

Did you remove `connection: local` this time? It would also be helpful if you show which task is failing.

As far as your inventory goes, I would expect something like this:

```yaml
Core_Switch:
  ansible_connection: network_cli
  ansible_network_os: ios
  ansible_user: ansible
  ansible_password: cisco123

```

where your password at least is vault encrypted, if not the whole file, unless you just want to enter it on the command line everytime you run the playbook.

These connection credentials for your host can be saved as host\_vars or group\_vars.

I don’t think you do, but you shouldn’t have `localhost` defined anywhere in inventory (that can break the implicit localhost). I just wanted to mention it because I was getting suspicious about it before.

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 27, 2024, 2:14pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/12 "2024-03-27T14:14:32Z")

</div>

@FELIXmu Hello,

The `cisco.ios.ios_command` module [supports `network_cli`](https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html#connections-available) connection plugin not `local`.

So you need to specify `ansible_connection` variable to `ansible.netcommon.network_cli` (or `connection` directive).

The following is an example:

`inventory.ini`:

```ini
[Core_Switch]
ios01 ansible_host=192.168.x.x

```

`group_vars/Core_Switch.yml`:

```yaml
---
ansible_network_os: cisco.ios.ios
ansible_connection: ansible.netcommon.network_cli
ansible_user: xxxxx
ansible_password: yyyyy

```

Playbook:

```yaml
- name: AUTOMATIC BACKUP OF RUNNING-CONFIG
  hosts: Core_Switch
  gather_facts: false

  tasks:
    - name: DISPLAYING THE RUNNING-CONFIG
      ios_command:
        commands:
          - show run
      register: config

    - name: Get Current Date
      command:
        cmd: date +%Y-%b-%d
      register: date
      delegate_to: localhost

    - name: Get Current Time
      command:
        cmd: date +%H:%M
      register: time
      delegate_to: localhost

    - name: Save Output to /home/user1/Backups
      copy:
        content: “{{ config.stdout[0] }}”
        dest: "/home/user1/Backups{{ date.stdout }}at{{ time.stdout }}-{{ inventory_hostname }}.txt"
      delegate_to: localhost

```

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 27, 2024, 2:17pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/13 "2024-03-27T14:17:43Z")

</div>

Sorry for the duplication.  
Most of what I am saying is the same as @Denney-tech .

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 27, 2024, 2:25pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/14 "2024-03-27T14:25:59Z")

</div>

Thank you for consolidating it into one post.

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [April 2, 2024, 5:49am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/15 "2024-04-02T05:49:43Z")

</div>

> [@akira6592](#):
>
> `ansible_connection: ansible.netcommon.network_cli`

[WARNING]: \* Failed to parse /etc/ansible/hosts with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON:  
Expecting value: line 1 column 1 (char 0) Syntax Error while loading YAML. did not find expected The error appears to be in  
‘/etc/ansible/hosts’: line 47, column 1, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be:

[WARNING]: \* Failed to parse /etc/ansible/hosts with ini plugin: /etc/ansible/hosts:64: Expected key=value, got: ansible\_network\_os: cisco.ios.ios  
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source  
[WARNING]: No inventory was parsed, only implicit localhost is available  
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: root@core\_switch: Permission denied (publickey,keyboard-interactive,password).”, “unreachable”: true}

Am getting errors above.

---

<div class="post-metadata">

**Author:** ![FELIXmu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixmu/32/2054_2.png) [@FELIXmu](https://forum.ansible.com/u/FELIXmu)\
**Post date:** [April 2, 2024, 6:15am UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/16 "2024-04-02T06:15:10Z")

</div>

localhost]: FAILED! =\> {“changed”: false, “msg”: “Connection type local is not valid for this module”}

when i change to use connection : local

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [April 5, 2024, 12:13pm UTC](https://forum.ansible.com/t/network-devices-backup-cisco-dell/4540/17 "2024-04-05T12:13:44Z")

</div>

@FELIXmu

Could you show us your inventory file to understand?  
If there is a password, mask it.
