I have been fighting with this for days now
This is my first ever dabble with ansible and I cannot get the simplest playbooks or even a ping to work.
Centos 7,
ansible 2.4.2.0
Juniper.junos module installed into ansible
I’m testing with a vSRX
I've read the day 1 guides
This is my error for every playbook I try to run
[root@localhost bin]# ansible -m ping all -vvv
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/ping.py
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<172.27.233.17> (0, '/root\n', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231 `" && echo ansible-tmp-1552552686.33-210239546229231="` echo /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231 `" ) && sleep 0'"'"''
<172.27.233.17> (0, 'ansible-tmp-1552552686.33-210239546229231=/root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231\n', '')
<172.27.233.17> PUT /tmp/tmp2WWXJi TO /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/ping.py
<172.27.233.17> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a '[172.27.233.17]'
<172.27.233.17> (0, 'sftp> put /tmp/tmp2WWXJi /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/ping.py\n', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/ /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/ping.py && sleep 0'"'"''
<172.27.233.17> (0, '', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a -tt 172.27.233.17 '/bin/sh -c '"'"'/usr/bin/python2.7 /root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/ping.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1552552686.33-210239546229231/" > /dev/null 2>&1 && sleep 0'"'"''
<172.27.233.17> (0, '/usr/bin/python2.7: not found\r\n', 'Shared connection to 172.27.233.17 closed.\r\n')
172.27.233.17 | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to 172.27.233.17 closed.\r\n",
"module_stdout": "/usr/bin/python2.7: not found\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}
So its saying python cannot be found but look
[root@localhost bin]# //usr/bin/python2.7
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
It looks like ansible usually runs something python on the remote device but this is not the case for network devices , surely we cannot be expected to install python on switches and routers ?.
My example playbook dies in the same way
[root@localhost ansible]# cat uptime3.yaml
---
- name: Get device uptime
hosts:
- VSRX1
roles:
- Juniper.junos
connection: local
gather_facts: no
vars_prompt:
- name: username
prompt: Junos Username
private: no
- name: password
prompt: Junos Password
private: yes
tasks:
- name: get uptime using galaxy module
juniper_junos_command:
commands:
- show system uptime
provider:
host: "{{ ansible_host }}"
port: 22
user: "{{ username }}"
passwd: "{{ password }}"
register: uptime
# - name: display uptimes (Python style)
# # debug:
# # var: uptime['stdout_lines']
#
# - name: display uptimes (Ansible shortcut)
# debug:
# var: uptime.stdout_lines
[root@localhost ansible]# ansible-playbook uptime3.yaml -vvv
ansible-playbook 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
PLAYBOOK: uptime3.yaml ********************************************************************************************************************************************
1 plays in uptime3.yaml
Junos Username: root
Junos Password:
PLAY [Get device uptime] ******************************************************************************************************************************************
META: ran handlers
TASK [get uptime using galaxy module] *****************************************************************************************************************************
task path: /etc/ansible/uptime3.yaml:20
Using module file /etc/ansible/roles/Juniper.junos/library/juniper_junos_command.py
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<172.27.233.17> (0, '/root\n', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832 `" && echo ansible-tmp-1552553226.63-178839703888832="` echo /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832 `" ) && sleep 0'"'"''
<172.27.233.17> (0, 'ansible-tmp-1552553226.63-178839703888832=/root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832\n', '')
<172.27.233.17> PUT /tmp/tmpowZMu1 TO /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/juniper_junos_command.py
<172.27.233.17> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a '[172.27.233.17]'
<172.27.233.17> (0, 'sftp> put /tmp/tmpowZMu1 /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/juniper_junos_command.py\n', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a 172.27.233.17 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/ /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/juniper_junos_command.py && sleep 0'"'"''
<172.27.233.17> (0, '', '')
<172.27.233.17> ESTABLISH SSH CONNECTION FOR USER: root
<172.27.233.17> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/7830714a9a -tt 172.27.233.17 '/bin/sh -c '"'"'/usr/bin/python2.7 /root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/juniper_junos_command.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1552553226.63-178839703888832/" > /dev/null 2>&1 && sleep 0'"'"''
<172.27.233.17> (0, '/usr/bin/python2.7: not found\r\n', 'Shared connection to 172.27.233.17 closed.\r\n')
fatal: [172.27.233.17]: FAILED! => {
"changed": false,
"module_stderr": "Shared connection to 172.27.233.17 closed.\r\n",
"module_stdout": "/usr/bin/python2.7: not found\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}
to retry, use: --limit @/etc/ansible/uptime3.retry
PLAY RECAP ********************************************************************************************************************************************************
172.27.233.17 : ok=0 changed=0 unreachable=0 failed=1
[root@localhost ansible]# ^C
Any pointers at all would be appreciated