# Ansible network

**URL:** <https://forum.ansible.com/t/ansible-network/26054>\
**Category:** Ansible Project\
**Created:** [November 17, 2017, 7:42am UTC](https://forum.ansible.com/t/ansible-network/26054 "2017-11-17T07:42:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://forum.ansible.com/u/SK1)\
**Post date:** [November 17, 2017, 7:42am UTC](https://forum.ansible.com/t/ansible-network/26054/1 "2017-11-17T07:42:23Z")

</div>

Hi,

I am using Ansible for the first time to test basic commands on Network devices. When I run the playbook, I am encountering errors even though the configuration looks normal. Below is the OS of my source machine where Ansible is installed:

CentOS Linux release 7.3.1611 (Core)

My ansible version is below:

ansible 2.3.2.0  
config file = /etc/ansible/ansible.cfg  
configured module search path = Default w/o overrides  
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

the config.yml file I am using to test is below:

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [November 17, 2017, 9:15am UTC](https://forum.ansible.com/t/ansible-network/26054/2 "2017-11-17T09:15:54Z")

</div>

Hi,

You need a space between the dash ‘-’ and ‘name:’ in the task list.  
I suggest you find a text editor that supports YAML validation to make your life easier.

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://forum.ansible.com/u/SK1)\
**Post date:** [November 21, 2017, 5:39am UTC](https://forum.ansible.com/t/ansible-network/26054/3 "2017-11-21T05:39:00Z")

</div>

Thank you for the suggestion about dash before name. I have updated that and still receive the same error. The error is pointing towards set\_fact. I will take a look into text editors for YAML.

ansible-playbook -vvvv configs.yml  
Using /etc/ansible/ansible.cfg as config file

ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/etc/ansible/configs.yml’: line 12, column 8, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: configure provider  
set\_fact:  
^ here

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [November 21, 2017, 7:31am UTC](https://forum.ansible.com/t/ansible-network/26054/4 "2017-11-21T07:31:18Z")

</div>

Now the issue is caused by indentation:

- name: configure provider  
set\_fact:

set\_fact must start at the same position as ‘name’ above it.

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://forum.ansible.com/u/SK1)\
**Post date:** [November 22, 2017, 7:58am UTC](https://forum.ansible.com/t/ansible-network/26054/5 "2017-11-22T07:58:41Z")

</div>

Hi Pshem,

Thank you again for the assistance, the indentation problem is now solved and the playbook is running, but with errors. I am back to the original question. How does ansible connect to the network device? Is it just username/password in the ansible configuration or do I need to setup any ssh keys on the Cisco network device for the Linux host running ansible to authenticate to device?

I ran the playbook command with -vvvv option as well and almost similar error in addition to “open\_shell() returned 255 failed to connect to control socket”

Host#ansible-playbook configs.yml

PLAY [DEPLOY SNMP CONFIGURATIONS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\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. Please see: [https://docs.ansible.com/ansible/network\_debug\_troubleshooting.html#unable-to-open-shell](https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell)”, “rc”: 255}**  
to retry, use: --limit @/etc/ansible/configs.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
sltnrmgmt : ok=1 changed=0 unreachable=0 failed=1

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [November 22, 2017, 8:35am UTC](https://forum.ansible.com/t/ansible-network/26054/6 "2017-11-22T08:35:18Z")

</div>

Hi,

Try this:

- name: DEPLOY SNMP COMMANDS WITHIN PB  
delegate\_to: localhost  
ios\_config:  
provider: “{{ provider }}”  
commands:
- snmp-server community Test1ng rw

(this is not tested)

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://forum.ansible.com/u/SK1)\
**Post date:** [November 23, 2017, 7:12am UTC](https://forum.ansible.com/t/ansible-network/26054/7 "2017-11-23T07:12:18Z")

</div>

Excellent! This worked now. What did this delegate\_to command actually do? Did the provider under ios\_config call the provider variables written already?

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [November 23, 2017, 7:19am UTC](https://forum.ansible.com/t/ansible-network/26054/8 "2017-11-23T07:19:20Z")

</div>

Hi,

delegate\_to forces the action to be carried out on the given host (in this case localhost). AFAIK all network commands must be executed on the controller (since usually the network devices don’t have a python interpreter).  
Yes, specifying provider like that refers to a variable, in this case a fact that you’ve set (which is a form of variable too).

kind regards  
Pshem
