Junos Automation (Scripting)
Junos Automation (Scripting)

[Ansible]Module unable to decode valid JSON on stdin

04.18.17   |  
‎04-18-2017 01:52 PM

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"

 

20 REPLIES
Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 02:27 AM

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

Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 03:25 AM

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}

 

Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 04:37 AM

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

 

Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 05:34 AM

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

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

 

Hope this helps.

Cheers,

Ashvin

Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 08:13 AM

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}

 

 

Junos Automation (Scripting)

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

04.19.17   |  
‎04-19-2017 08:56 AM

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.

Junos Automation (Scripting)

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

04.21.17   |  
‎04-21-2017 12:13 PM

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

Junos Automation (Scripting)

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

[ Edited ]
04.30.17   |  
‎04-30-2017 09:18 AM

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

Junos Automation (Scripting)

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

04.30.17   |  
‎04-30-2017 02:08 PM

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

Junos Automation (Scripting)

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

05.09.17   |  
‎05-09-2017 12:11 PM

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;
}

 

Junos Automation (Scripting)

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

05.09.17   |  
‎05-09-2017 12:26 PM

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

 

Regards,

Andy

Junos Automation (Scripting)

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

05.10.17   |  
‎05-10-2017 12:50 AM

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

Junos Automation (Scripting)

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

05.16.17   |  
‎05-16-2017 07:07 PM
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}
Highlighted
Junos Automation (Scripting)

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

05.18.17   |  
‎05-18-2017 05:54 PM

Hi, 

 

Could you confirm the versions again please:

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

Cheers,

Ashvin

Junos Automation (Scripting)

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

06.07.17   |  
‎06-07-2017 09:40 AM

Hi sorry to hi-jack this thread but I have a very similar problem. Couple of playbooks run through fine until it gets to the task.

 

TASK [Retrieve Juniper Facts] *******************************************************************
task path: /etc/ansible/work/jfacts.yml:13

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

 

 

pip list | grep junos

junos-eznc (1.1.2)

 

ansible-galaxy list
- Juniper.junos, 1.4.2

 

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.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

 

Cheers

Junos Automation (Scripting)

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

06.07.17   |  
‎06-07-2017 12:30 PM

Hi, 

 

Since you are using Ansible 2.3, I'd suggest updating to latest PyEz [v2.1.3 latest].

https://github.com/Juniper/py-junos-eznc

 

Cheers,

Ashvin

Junos Automation (Scripting)

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

[ Edited ]
06.08.17   |  
‎06-08-2017 11:09 AM

Hi OK thank you.

 

I upgraded pyez and I still get the same issue, see below. So I uninstalled ansible 2.3.0 and installed 2.2.3.0 (pip install -I ansible==2.2.3.0) and that fixes it. I have read around and posts about similar issues infer that bad modules are to blame?

 

Version info when not working:

 

pip list | grep junos
junos-eznc (2.1.3)

 

ansible-galaxy list
- Juniper.junos, 1.4.2
- cumulus.CumulusLinux, 2.2.1

 

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.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

Then a run of a playbook.

 

ansible-playbook jfacts.yml


PLAY [Testing Juniper and Ansible] **************************************************************************

TASK [Verifying NETCONF] ************************************************************************************
ok: [vmx4]
ok: [vmx3]
ok: [vmx1]
ok: [vmx2]
ok: [vmx5]
ok: [vmx6]
ok: [vmx7]
ok: [ash01-r1]
ok: [oak01-r1]
ok: [oak02-r1]
ok: [ash02-r1]

TASK [Retrieve Juniper Facts] *******************************************************************************

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

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

 

Using verbose switch the TASK failure is below (truncated but output is just a repeat several times of the same "msg"):

 

 TASK [Retrieve Juniper Facts] *******************************************************************************
task path: /etc/ansible/work/jfacts.yml:13


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

Junos Automation (Scripting)

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

[ Edited ]
06.08.17   |  
‎06-08-2017 12:08 PM

Please share your playbook.  Specifically this task: Retrieve Juniper Facts

 

I'm not having any issues with MX960s (13.3R3) and EX4300's (15.1R4).

 

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

pip list | grep junos
junos-eznc (2.1.2)
junos-netconify (1.0.3)

ansible-galaxy list
- Juniper.junos, 1.4.2

Thanks.

Junos Automation (Scripting)

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

06.10.17   |  
‎06-10-2017 05:47 AM

Hi - here's one of the playbooks:

 

---
- name: Testing Juniper and Ansible
  hosts: JUNIPER
  roles:
   - Juniper.junos
  connection: local
  gather_facts: no

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

    - name: Retrieve Juniper Facts
      junos_get_facts:
        host={{ inventory_hostname }}
      register: junos 

    - name: Print vmx-srx information
      debug: msg="MODEL {{ junos.facts.model }} | SOFTWARE {{ junos.facts.version }} | S/N {{ junos.facts.serialnumber }}"

Thanks in advance.

 

Cheers