Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

ansible-palybook error

‎07-31-2018 11:06 AM

Hi ,

I'd like to upgrade junos with ansible , but I got error as below

ansible-playbook -i inventory.yml junos-upgrade.yml

PLAY [Install Junos OS] *****************************************************************************************************************************************************************************************************************

TASK [Install Junos OS package] *********************************************************************************************************************************************************************************************************
fatal: [srx240h]: FAILED! => {"changed": false, "msg": "Unable to open the log file /var/log/ansible/software.log. [Errno 2] No such file or directory: '/var/log/ansible/software.log'"}
to retry, use: --limit @/home/jkim3/ansible-test/junos-upgrade.retry

PLAY RECAP ******************************************************************************************************************************************************************************************************************************
srx240h : ok=0 changed=0 unreachable=0 failed=1

 

Here is my yml file.

---
- name: Install Junos OS
hosts: 4751-srx
roles:
- juniper.junos
connection: local
gather_facts: no

vars:
OS_version: "12.1X46-D76"
OS_package: "junos-srxsme-12.1X46-D76-domestic.tgz"
pkg_dir: "software"
log_dir: "/var/log/ansible"
netconf_port: 830
wait_time: 3600

tasks:
- name: Install Junos OS package
juniper_junos_software:
version: "{{ OS_version }}"
local_package: "{{ pkg_dir }}/{{ OS_package }}"
reboot: true
validate: true
logfile: "{{ log_dir }}/software.log"
register: sw
notify:
- wait_reboot

- name: Print response
debug:
var: sw


handlers:
- name: wait_reboot
wait_for:
host: "{{ inventory_hostname }}"
port: "{{ netconf_port }}"
timeout: "{{ wait_time }}"
when: not sw.check_mode

 

 

4 REPLIES 4
Highlighted
Junos Automation (Scripting)

Re: ansible-palybook error

‎07-31-2018 02:57 PM

Hi,

 

Does /var/log/ansible/ exist and is it writable by the user that you are executing the playbook?

 

Tim

Highlighted
Junos Automation (Scripting)

Re: ansible-palybook error

‎08-03-2018 03:12 PM

[jkim3@ipam01 ansible]$ ls -al
total 4
drwxr-xr-x 2 root root 26 Aug 1 12:14 .
drwxr-xr-x. 10 root root 4096 Aug 1 12:13 ..
-rw-r--r-- 1 root root 0 Aug 1 12:14 software.log
[jkim3@ipam01 ansible]$
[jkim3@ipam01 ansible]$ pwd
/var/log/ansible
[jkim3@ipam01 ansible]$

 

When I run with debug mode , I got error as follow.

 

[jkim3@ipam01 ansible-test]$ !ansi
ansible-playbook -vvvv -i inventory.yml junos-upgrade.yml
ansible-playbook 2.6.2
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/jkim3/.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, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /home/jkim3/ansible-test/inventory.yml inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc
Loading callback plugin jsnapy of type aggregate, v2.0 from /etc/ansible/roles/juniper.junos/callback_plugins/jsnapy.pyc

PLAYBOOK: junos-upgrade.yml *************************************************************************************************************************************************************************************************************
1 plays in junos-upgrade.yml

PLAY [Install Junos OS] *****************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Checking NETCONF connectivity] ****************************************************************************************************************************************************************************************************
task path: /home/jkim3/ansible-test/junos-upgrade.yml:18
<10.254.1.20> ESTABLISH LOCAL CONNECTION FOR USER: jkim3
<10.254.1.20> EXEC /bin/sh -c 'echo ~jkim3 && sleep 0'
<10.254.1.20> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642 `" && echo ansible-tmp-1533334097.11-94175712109642="` echo /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642 `" ) && sleep 0'
Using module file /usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.py
<10.254.1.20> PUT /home/jkim3/.ansible/tmp/ansible-local-19477U0hmo6/tmpWOoKyH TO /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642/wait_for.py
<10.254.1.20> EXEC /bin/sh -c 'chmod u+x /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642/ /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642/wait_for.py && sleep 0'
<10.254.1.20> EXEC /bin/sh -c '/usr/bin/python /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642/wait_for.py && sleep 0'
<10.254.1.20> EXEC /bin/sh -c 'rm -f -r /home/jkim3/.ansible/tmp/ansible-tmp-1533334097.11-94175712109642/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
File "/tmp/ansible_i9rJ0q/ansible_module_wait_for.py", line 540, in main
s = _create_connection(host, port, min(connect_timeout, alt_connect_timeout))
File "/tmp/ansible_i9rJ0q/ansible_module_wait_for.py", line 405, in _create_connection
connect_socket = socket.create_connection((host, port), connect_timeout)
File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
raise err
fatal: [srx240h]: FAILED! => {
"changed": false,
"elapsed": 6,
"invocation": {
"module_args": {
"active_connection_states": [
"ESTABLISHED",
"FIN_WAIT1",
"FIN_WAIT2",
"SYN_RECV",
"SYN_SENT",
"TIME_WAIT"
],
"connect_timeout": 5,
"delay": 0,
"exclude_hosts": null,
"host": "10.254.1.20",
"msg": null,
"path": null,
"port": 830,
"search_regex": null,
"sleep": 1,
"state": "started",
"timeout": 5
}
},
"msg": "Timeout when waiting for 10.254.1.20:830"
}
to retry, use: --limit @/home/jkim3/ansible-test/junos-upgrade.retry

PLAY RECAP ******************************************************************************************************************************************************************************************************************************
srx240h : ok=0 changed=0 unreachable=0 failed=1

 

 

 

 

 

Highlighted
Junos Automation (Scripting)

Re: ansible-palybook error

‎08-06-2018 12:48 PM
 

Attachments

Highlighted
Junos Automation (Scripting)

Re: ansible-palybook error

‎08-06-2018 12:51 PM

I have attched my yml file as follow.

 

According to my debug and software.log  , i got junos mount error.

 

---
- name: Install Junos OS
hosts: 4751-srx
roles:
- juniper.junos
connection: local
gather_facts: no

vars:
OS_version: "12.1X46-D76"
OS_package: "junos-srxsme-12.1X46-D76-domestic.tgz"
pkg_dir: "../software"
log_dir: "/var/log/ansible"
netconf_port: 830
wait_time: 3600

tasks:
# - name: Checking NETCONF connectivity
# wait_for:
# host: "{{ ansible_host }}"
# port: "{{ netconf_port }}"
# timeout: 5


- name: Install Junos OS package
juniper_junos_software:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
passwd: "{{ ansible_ssh_pass }}"
version: "{{ OS_version }}"
local_package: "{{ pkg_dir }}/{{ OS_package }}"
reboot: true
validate: true
logfile: "{{ log_dir }}/software.log"
register: sw
notify:
- wait_reboot

- name: Print response
debug:
var: sw


handlers:
- name: wait_reboot
wait_for:
host: "{{ ansible_host }}"
port: "{{ netconf_port }}"
timeout: "{{ wait_time }}"
when: not sw.check_mode


~

Attachments

Feedback