I am trying to create dynamic inventory for my setup. everywhere i see examples of IPs and hostname as list. but when i provide hosts value as list it error's out and says it has to be dict.
Below inventory i am providing to playbook,
{
"all": {
"hosts": ["192.168.1.2", "192.168.1.3", "192.168.1.4"],
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
},
"webserver": {
"hosts": ["192.168.1.3", "192.168.1.4"],
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
},
"dbserver": {
"hosts": ["192.168.1.2"],
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
}
}
it gives this warnning and error
[WARNING]: * Failed to parse /Users/rahulbhatu/playbooks/waf-
playbooks/inventory with yaml plugin: Invalid "hosts" entry for "all" group,
requires a dictionary, found "<type 'list'>" instead.
[WARNING]: * Failed to parse /Users/rahulbhatu/playbooks/waf-
playbooks/inventory with ini plugin: Invalid host pattern 'all:' supplied,
ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /Users/rahulbhatu/playbooks/waf-playbooks/inventory
as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available```
fatal: [{]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname {: nodename nor servname provided, or not known", "unreachable": true}
Howeever when i pass it this way as a dict and value as null it works, can someone help me what i am missing as.
"all": {
"hosts": {
"192.168.1.2": null,
"192.168.1.3" : null,
"192.168.1.4" : null
},
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
},
"webserver": {
"hosts": {
"192.168.1.3": null,
"192.168.1.4": null
},
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
},
"dbserver": {
"hosts": {
"192.168.1.2": null
},
"vars": {
"ansible_ssh_user": "root"
},
"_meta": {
"hostvars": {}
}
}
}