# Ansible-2.1.0 - "connection=local" does not work

**URL:** <https://forum.ansible.com/t/ansible-2-1-0-connection-local-does-not-work/21731>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [June 10, 2016, 11:57am UTC](https://forum.ansible.com/t/ansible-2-1-0-connection-local-does-not-work/21731 "2016-06-10T11:57:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cuong\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Cuong\_Nguyen](https://forum.ansible.com/u/Cuong_Nguyen)\
**Post date:** [June 10, 2016, 11:57am UTC](https://forum.ansible.com/t/ansible-2-1-0-connection-local-does-not-work/21731/1 "2016-06-10T11:57:54Z")

</div>

Hi all,

I am using Ansible 2.1.0 on Ubuntu. I’m trying to use “ **ios\_command** ” to execute command on Cisco router.

In playbook, I set connection to local ( **connection=local** ). However, when run ansible-playbook, ansible still tries to copy temporary file onto router; which resulted in Ansible’s inability to execute the command:

`

**ansible\_user@sp-mgmt:~/example$** ansible\_user@sp-mgmt:~/example$ ansible-playbook -vvv -i production showconfig.yml  
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: showconfig.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in showconfig.yml

PLAY [pe2] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [OBTAIN LOGIN CREDENTIALS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:7  
ok: [pe2] =\> {“ansible\_facts”: {“creds”: {“auth\_pass”: “cisco”, “password”: “cisco”, “username”: “cisco”}}, “changed”: false, “invocation”: {“module\_args”: {“\_raw\_params”: “secrets.yml”}, “module\_name”: “include\_vars”}}

TASK [DEFINE PROVIDER] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:10  
ok: [pe2] =\> {“ansible\_facts”: {“provider”: {“auth\_pass”: “cisco”, “host”: “pe2”, “password”: “cisco”, “username”: “cisco”}}, “changed”: false, “invocation”: {“module\_args”: {“provider”: {“auth\_pass”: “cisco”, “host”: “pe2”, “password”: “cisco”, “username”: “cisco”}}, “module\_name”: “set\_fact”}}

TASK [RUN ‘SHOW CLOCK’] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:18  
 ESTABLISH SSH CONNECTION FOR USER: cisco  
 SSH: EXEC sshpass -d12 ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o User=cisco -o ConnectTimeout=10 -o ControlPath=/home/ansible\_user/.ansible/cp/ansible-ssh-%h-%p-%r pe2 ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1465559648.05-58745276585938`” && echo ansible-tmp-1465559648.05-58745276585938=“`echo $HOME/.ansible/tmp/ansible-tmp-1465559648.05-58745276585938`” ) && sleep 0’“'”‘’  
 PUT /tmp/tmpfKgbw1 TO “`echo $HOME/.ansible/tmp/ansible-tmp-1465559648.05-58745276585938`” ) && sleep 0’"/ios\_command  
 SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o User=cisco -o ConnectTimeout=10 -o ControlPath=/home/ansible\_user/.ansible/cp/ansible-ssh-%h-%p-%r ‘[pe2]’  
fatal: [pe2]: UNREACHABLE! =\> {“changed”: false, “msg”: “SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh”, “unreachable”: true}  
to retry, use: --limit @showconfig.retry

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

`

When executed with option “ **-e ansible\_connection=local** ”, Ansible was able to complete the task:

`

**ansible\_user@sp-mgmt:~/example$** ansible-playbook -vvv -i production -e ansible\_connection=local showconfig.yml  
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: showconfig.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in showconfig.yml

PLAY [pe2] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [OBTAIN LOGIN CREDENTIALS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:7  
ok: [pe2] =\> {“ansible\_facts”: {“creds”: {“auth\_pass”: “cisco”, “password”: “cisco”, “username”: “cisco”}}, “changed”: false, “invocation”: {“module\_args”: {“\_raw\_params”: “secrets.yml”}, “module\_name”: “include\_vars”}}

TASK [DEFINE PROVIDER] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:10  
ok: [pe2] =\> {“ansible\_facts”: {“provider”: {“auth\_pass”: “cisco”, “host”: “pe2”, “password”: “cisco”, “username”: “cisco”}}, “changed”: false, “invocation”: {“module\_args”: {“provider”: {“auth\_pass”: “cisco”, “host”: “pe2”, “password”: “cisco”, “username”: “cisco”}}, “module\_name”: “set\_fact”}}

TASK [RUN ‘SHOW CLOCK’] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:18  
 ESTABLISH LOCAL CONNECTION FOR USER: ansible\_user  
 EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1465559709.41-163188613042417`” && echo ansible-tmp-1465559709.41-163188613042417=“`echo $HOME/.ansible/tmp/ansible-tmp-1465559709.41-163188613042417`” ) && sleep 0’  
 PUT /tmp/tmpmiqoJ6 TO /home/ansible\_user/.ansible/tmp/ansible-tmp-1465559709.41-163188613042417/ios\_command  
 EXEC /bin/sh -c ‘LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /home/ansible\_user/.ansible/tmp/ansible-tmp-1465559709.41-163188613042417/ios\_command; rm -rf “/home/ansible\_user/.ansible/tmp/ansible-tmp-1465559709.41-163188613042417/” \> /dev/null 2\>&1 && sleep 0’  
ok: [pe2] =\> {“changed”: false, “invocation”: {“module\_args”: {“auth\_pass”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”, “authorize”: false, “commands”: [“show clock”], “host”: “pe2”, “interval”: 1, “password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”, “port”: 22, “provider”: “{‘username’: ‘ **', ‘password’: '** ’, ‘host’: ‘pe2’, ‘auth\_pass’: ‘\*\*\*\*\*\*\*\*’}”, “retries”: 10, “ssh\_keyfile”: null, “timeout”: 10, “username”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”, “waitfor”: null}, “module\_name”: “ios\_command”}, “stdout”: [“\*19:52:39.860 SGT Fri Jun 10 2016”], “stdout\_lines”: [[“\*19:52:39.860 SGT Fri Jun 10 2016”]]}

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ansible\_user/example/showconfig.yml:25  
ok: [pe2] =\> {  
“version.stdout\_lines”: [  
[  
“\*19:52:39.860 SGT Fri Jun 10 2016”  
]  
]  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
pe2 : ok=4 changed=0 unreachable=0 failed=0

`

Is it some sorts of a bug? Or is it because of my playbook settings? Below are the configurations

`

ansible\_user@sp-mgmt:~/example$ cat production  
[pe]  
pe[1:6]

[p]  
p1[1:2]  
p2[1:4]

[ce]  
ce[1:6]

[all:vars]  
ansible\_connection=ssh  
ansible\_user=cisco  
ansible\_ssh\_pass=cisco

ansible\_user@sp-mgmt:~/example$ cat secrets.yml—  
creds:  
username: cisco  
password: cisco  
auth\_pass: cisco

ansible\_user@sp-mgmt:~/example$ cat showconfig.yml

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 10, 2016, 8:01pm UTC](https://forum.ansible.com/t/ansible-2-1-0-connection-local-does-not-work/21731/2 "2016-06-10T20:01:53Z")

</div>

No bug, the ansible\_connection variable just has higher precedence than the connection directive, since you have `ansible_connection=ssh` in inventory, it ignores the `connection: local` you have in the task.
