Junos Automation (Scripting)
Showing results for 
Search instead for 
Do you mean 
Reply
MYN
Contributor
Posts: 28
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"

 

Trusted Expert
Posts: 544
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: 28
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}

 

Trusted Expert
Posts: 544
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

 

Trusted Expert
Posts: 544
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: 28
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: 28
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.

Highlighted
Trusted Expert
Posts: 544
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