0
votes

I am using below dynamic inventory file(JSON) and the Playbook YML. I am not able to execute it. Getting an error. Need your inputs.

my_dynamic_inventory --list
{
    "_meta": {
        "hostvars": {
            Node_001": {
                "model_name":"router1",
                "ansible_user":"xxx",
                "ansible_password":"xxx",
                "ansible_port":"20",
                "ansible_host":"172.xx.xx.xx",
                "snmp_version":"2c",
                "snmp_community":"public",
                "snmp_port":"yyyy",
                "stack_node_num":"5"
                "ansible_network_os":"moduleA"
            }
        },
    },
    "all": {
        "hosts": ["Node_001"]
    }
}

YML file:

---
- hosts: all
  gather_facts: off
  connection: local
  tasks:
    - name: create vlan entry
      necqx_vlan:
        vlan_id: 194
        name: VLAN1
        state: present
        model: router1

When I execute the play book with the dynamic inventory file I am getting below error

[WARNING]: * Failed to parse /Path_to_dynamic_inventory/dynamic_inventory with ini plugin: /Path_to_dynamic_inventory/dynamic_inventory:1: Expected key=value host variable assignment, got: --list

File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py", line 132, in parse self._parse(path, data) File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py", line 210, in _parse hosts, port, variables = self._parse_host_definition(line) File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py", line 308, in _parse_host_definition self._raise_error("Expected key=value host variable assignment, got: %s" % (t)) File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py", line 137, in _raise_error raise AnsibleError("%s:%d: " % (self._filename, self.lineno) + message)

[WARNING]: Unable to parse /Path_to_dynamic_inventory/dynamic_inventory as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

.... ...

PLAY [all] **************************************************************************************************************

skipping: no hosts matched

2
A static JSON file with flawed syntax is not a "dynamic inventory". Ansible told you that my_dynamic_inventory --list is not valid JSON syntax.techraf
@Tejas Let us know if you're still having an issue. :)Michael Ababio

2 Answers

0
votes

There appears to be some typos in the generated json. Like more error messages, the one given is very cryptic. I would validate my json in situations like this. Try jsonlint cli or online json validator.

A comma is missing:

"stack_node_num":"5"
"ansible_network_os":"moduleA"

A missing open parenthesis:

 Node_001": {
0
votes

This is a path problem. Cannot find the dynamic inventory as it is shown in the error.

By the way:

You need to change the:

Node_001": { ... }

to

"Node_001": { ... }

Basically you forgot the ". And then later since you want to refer to that, you need to get the value of that. (like a variable).