Junos Automation (Scripting)
Showing results for 
Search instead for 
Do you mean 
Reply
MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

[Ansible]Module unable to decode valid JSON on stdin

Hi,

 

I'm trying to run Ansible script to change the domain-name on SRX. basically, I'm testing it so that later can add more configuration but I ran into error. 

 

 

{"msg": "Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed", "failed": true}

 

My set file contains this text, I have tied using .set extension as well and got same error.

 

yasir@yasir-VM:/etc/ansible/roles/Juniper.junos/tasks$ cat /home/yasir/Ansible_labs/juniper/set-domain.conf
set system domain-name test.com

Host Details

 

 

 

yasir@yasir-VM:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty



yasir@yasir-VM:~$ python --version
Python 2.7.6


yasir@yasir-VM:~$ ansible --version
ansible 2.3.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

 

 

Here is the error message, I ran ansible in verbose mode to have more details

yasir@yasir-VM:/etc/ansible/roles/Juniper.junos/tasks$ ansible-playbook SET.yml -vvvv
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc
Loading callback plugin jsnapy of type aggregate, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: SET.yml *******************************************************************************************
1 plays in SET.yml

PLAY [SET] **************************************************************************************************
META: ran handlers

TASK [CHECK-NETCONF] ****************************************************************************************
task path: /etc/ansible/roles/Juniper.junos/tasks/SET.yml:12
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/utilities/logic/wait_for.py
<192.168.56.103> ESTABLISH LOCAL CONNECTION FOR USER: yasir
<192.168.56.103> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.56.103> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558 `" && echo ansible-tmp-1492548249.79-279977122145558="` echo /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558 `" ) && sleep 0'
<192.168.56.103> PUT /tmp/tmp0NUEpw TO /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py
<192.168.56.103> EXEC /bin/sh -c 'chmod u+x /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/ /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py && sleep 0'
<192.168.56.103> EXEC /bin/sh -c '/usr/bin/python /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py; rm -rf "/home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/" > /dev/null 2>&1 && sleep 0'
ok: [192.168.56.103] => {
    "changed": false, 
    "elapsed": 0, 
    "invocation": {
        "module_args": {
            "active_connection_states": [
                "ESTABLISHED", 
                "SYN_SENT", 
                "SYN_RECV", 
                "FIN_WAIT1", 
                "FIN_WAIT2", 
                "TIME_WAIT"
            ], 
            "connect_timeout": 5, 
            "delay": 0, 
            "exclude_hosts": null, 
            "host": "192.168.56.103", 
            "path": null, 
            "port": 22, 
            "search_regex": null, 
            "sleep": 1, 
            "state": "started", 
            "timeout": 300
        }
    }, 
    "path": null, 
    "port": 22, 
    "search_regex": null, 
    "state": "started"
}

TASK [SET-DOMAIN] *******************************************************************************************
task path: /etc/ansible/roles/Juniper.junos/tasks/SET.yml:15

{"msg": "Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed", "failed": true}

 

Here is my yml file

 

 

---
- name: SET
  hosts: 192.168.56.103
  roles:
  - Juniper.junos
  connection: local
  gather_facts: no
 
  # Execute tasks (plays) this way "ansible-playbook <path>/SET.yml --tags <tag-name>"
  tasks:
  # Check if a device is NETCONF-aware
  - name: CHECK-NETCONF
    tags: check-netconf
    wait_for: host="{{ inventory_hostname }}" port="{{ juniper_port }}"
  - name: SET-DOMAIN
    tags: set-domain
    junos_install_config: host="{{ inventory_hostname }}" user="{{ juniper_user }}" port="{{ juniper_port }}"
     comment="Setup domain-name"
     file="/home/yasir/Ansible_labs/juniper/set-domain.conf"

 

Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi, 

 

It seems the parameters specified in SET-DOMAIN task are not being accepted.

The following worked for me:

---
- name: SET
  hosts: SRX01
  roles:
  - Juniper.junos
  connection: local
  gather_facts: no

  # Execute tasks (plays) this way "ansible-playbook <path>/SET.yml --tags <tag-name>"
  tasks:
  - name: Checking NETCONF Connectivity
    wait_for: host={{ inventory_hostname }} port=830 timeout=5

  - name: SET-DOMAIN
    tags: set-domain
    junos_install_config: host="{{ inventory_hostname }}" user="{{ ansible_ssh_user }}"
     comment="Setup domain-name"
     file="set-domain.set"
     replace="false"
     overwrite="false"

For set commands, the file extension needs to be .set, otherwise it throws an error:

"msg": "Unable to load config: ConfigLoadError(severity: error, bad_element: set, message: error: syntax error)"

Hope this helps.

 

Cheers,

Ashvin

MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi Ashvin,

 

Thanks for your time to reply. However, it didn't help

 

yasir@yasir-VM:~/Ansible_labs/juniper$ ls
set-domain.set
yasir@yasir-VM:~/Ansible_labs/juniper$ cat set-domain.set 
set system domain-name test.com

Still received same error message 

TASK [SET-DOMAIN] **********************************************************************************************************************************************

{"msg": "Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed", "failed": true}

 

Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi, 

 

The error is in to the playbook. Could you try changing the SET-DOMAIN task to:

 

  - name: SET-DOMAIN
    tags: set-domain
    junos_install_config: host="{{ inventory_hostname }}" user="{{ juniper_user }}"
     comment="Setup domain-name"
     file="/home/yasir/Ansible_labs/juniper/set-domain.set"
     replace="false"
     overwrite="false"

Also, do you have "juniper_user" defined as a variable.

 

Cheers,

Ashvin

 

Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Also, since you are using Ansible2.3, please check:

https://github.com/ansible/ansible/issues/23725

 

Hope this helps.

Cheers,

Ashvin

MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi Ashish,

 

Thanks again. Here is the hosts file config

 

[SRX]
192.168.56.103
[JUNIPER:children]
SRX
[JUNIPER:vars]
juniper_user=ansible
juniper_port=22





SSH works fine

yasir@yasir-VM:~$ ssh ansible@192.168.56.103
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
ansible@vsrx-1> 

Error is same again

yasir@yasir-VM:/etc/ansible/roles/Juniper.junos/tasks$ ansible-playbook SET.yml 

PLAY [SET] ****************************************************************************************************************************************************

TASK [SET-DOMAIN] *********************************************************************************************************************************************

{"msg": "Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed", "failed": true}

 

 

MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Well, I followed this URL https://github.com/ansible/ansible/issues/23725 but after that I ran into another bug which is 

 

The error appears to have been in '/etc/ansible/roles/Juniper.junos/tasks/SET.yml': line 16, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

Details are available on this link

 

https://github.com/ansible/ansible/issues/16456

 

I will prepare CentOS to further test it.

Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi, 

 

Could you share the playbook SET.yml and the complete error msg.

Alternatively, you could use prior versions of ansible. Ansible 2.3 is very recent i understand.

I can confirm it works on Ansible2.2.1.0.

 

Cheers,
Ashvin

MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

[ Edited ]

Hi Ashvin,

 

Thanks for following up and interest in this issue. Same script has worked for me with previous versions of Ansible.

 

 

 

Ideally, If there is an update in ansible and have issues, it needs to be rectified.

 

Thanks,

MYN

Recognized Expert
Posts: 319
Registered: ‎10-04-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi,

 

This all sounds very much like the correct versions are needed.

 

Grab the latest PyEz and ansible-junos-stdlib modules, they should be fine for Ansible 2.3.

 

Release 1.4.2 of the Juniper.junos module which supports Ansible 2.3 was only recently released (6 days ago)

 

You will probably need to perform;

sudo ansible-galaxy remove Juniper.junos
sudo ansible-galaxy install Juniper.junos

Regards,

Andy

Visitor
Posts: 1
Registered: ‎06-14-2016
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

i still have this same issue....

 

 

[mdisher@ubuntu64vm ansible-junos-stdlib-1.1.0]$ ansible-playbook -i hosts juniper-srx.yml

PLAY [Load merge a configuration to a device running Junos OS] ************************************************

TASK [Checking NETCONF connectivity] **************************************************************************
ok: [firewall.disher.net]

TASK [load merge a configuration file] ************************************************************************

{"msg": "Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed", "failed": true}
^C [ERROR]: User interrupted execution

 

Very simplistic tests:

 

local hosts file:

[mdisher@ubuntu64vm ansible-junos-stdlib-1.1.0]$ cat hosts
[dishernet]
firewall.disher.net ansible_ssh_host=10.100.1.1

 

very simple playbook:

[mdisher@ubuntu64vm ansible-junos-stdlib-1.1.0]$ cat juniper-srx.yml
- name: Load merge a configuration to a device running Junos OS
hosts: firewall.disher.net
roles:
- Juniper.junos
connection: local
gather_facts: no

tasks:
- name: Checking NETCONF connectivity
wait_for: host={{ inventory_hostname }} port=830 timeout=5

- name: load merge a configuration file
junos_install_config:
host={{ inventory_hostname }}
file=update-hostname.conf
overwrite=false
logfile=update_config.log
diffs_file=deploysitediffs.logs

 

simple config change:

 

[mdisher@ubuntu64vm ansible-junos-stdlib-1.1.0]$ cat update-hostname.conf
system {
host-name DisherSRX300PAnsibled;
}

 

Recognized Expert
Posts: 319
Registered: ‎10-04-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Which versions of PyEz and the Juniper.junos Ansible modules do you now have installed?

 

Regards,

Andy

Highlighted
Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi,

 

Could you try running the playbook in verbose mode to look at the parameters being passed.

ansible-playbook -vvv -i hosts juniper-srx.yml

 

Also please confirm the versions being used.

 

Cheers,

Ashvin

MYN
Contributor
Posts: 30
Registered: ‎07-06-2015
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

yasir@yasir-VM:/etc/ansible/roles/Juniper.junos/tasks$ ansible-playbook SET.yml -vvvv
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc
Loading callback plugin jsnapy of type aggregate, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: SET.yml *******************************************************************************************
1 plays in SET.yml

PLAY [SET] **************************************************************************************************
META: ran handlers

TASK [CHECK-NETCONF] ****************************************************************************************
task path: /etc/ansible/roles/Juniper.junos/tasks/SET.yml:12
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/utilities/logic/wait_for.py
<192.168.56.103> ESTABLISH LOCAL CONNECTION FOR USER: yasir
<192.168.56.103> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.56.103> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558 `" && echo ansible-tmp-1492548249.79-279977122145558="` echo /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558 `" ) && sleep 0'
<192.168.56.103> PUT /tmp/tmp0NUEpw TO /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py
<192.168.56.103> EXEC /bin/sh -c 'chmod u+x /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/ /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py && sleep 0'
<192.168.56.103> EXEC /bin/sh -c '/usr/bin/python /home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/wait_for.py; rm -rf "/home/yasir/.ansible/tmp/ansible-tmp-1492548249.79-279977122145558/" > /dev/null 2>&1 && sleep 0'
ok: [192.168.56.103] => {
    "changed": false, 
    "elapsed": 0, 
    "invocation": {
        "module_args": {
            "active_connection_states": [
                "ESTABLISHED", 
                "SYN_SENT", 
                "SYN_RECV", 
                "FIN_WAIT1", 
                "FIN_WAIT2", 
                "TIME_WAIT"
            ], 
            "connect_timeout": 5, 
            "delay": 0, 
            "exclude_hosts": null, 
            "host": "192.168.56.103", 
            "path": null, 
            "port": 22, 
            "search_regex": null, 
            "sleep": 1, 
            "state": "started", 
            "timeout": 300
        }
    }, 
    "path": null, 
    "port": 22, 
    "search_regex": null, 
    "state": "started"
}

TASK [SET-DOMAIN] *******************************************************************************************
task path: /etc/ansible/roles/Juniper.junos/tasks/SET.yml:15

{"msg": "Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed", "failed": true}
Distinguished Expert
Posts: 555
Registered: ‎08-15-2012
0 Kudos

Re: [Ansible]Module unable to decode valid JSON on stdin

Hi, 

 

Could you confirm the versions again please:

ansible --version
ansible-galaxy list
pip list | grep junos

Cheers,

Ashvin