On 11/3/20 11:03 AM, [email protected] wrote:
> Thanks Vladimir,
> 
> When I take out the trailing comma on line 7 I get a different error:
> 
> $ ./dynamic1.sh
> {
>   "all": {
>       "hosts": {
> "ip-172-31-39-30.eu-west-1.compute.internal": null,
> "ip-172-31-44-224.eu-west-1.compute.internal": null,
> "ip-172-31-42-6.eu-west-1.compute.internal": null,
> "ip-172-31-32-68.eu-west-1.compute.internal": null
>     }
>   }
> }

hosts should be a list, not a dict, e.g.

{
    "group": {
        "hosts": [
            "192.168.28.71",
            "192.168.28.72"
        ],
        "vars": {
            "ansible_ssh_user": "johndoe",
            "ansible_ssh_private_key_file": "~/.ssh/mykey",
            "example_variable": "value"
        }
    },
    "_meta": {
        "hostvars": {
            "192.168.28.71": {
                "host_specific_var": "bar"
            },
            "192.168.28.72": {
                "host_specific_var": "foo"
            }
        }
    }
}

Example from: 
https://www.jeffgeerling.com/blog/creating-custom-dynamic-inventories-ansible

Regards
        Racke

> $ ansible -i ./dynamic1.sh all -m ping -u ubuntu
> [WARNING]:  * Failed to parse /home/ubuntu/dynamic1.sh with script plugin: 
> You defined a group 'all' with bad data for
> the host list:  {u'hosts': {u'ip-172-31-32-68
> .eu-west-1.compute.internal': None, 
> u'ip-172-31-39-30.eu-west-1.compute.internal': None,
> u'ip-172-31-42-6.eu-west-1.compute.internal': None, u'ip-172-31-44-224.eu-
> west-1.compute.internal': None}}
> [WARNING]:  * Failed to parse /home/ubuntu/dynamic1.sh with ini plugin: 
> /home/ubuntu/dynamic1.sh:3: Expected key=value
> host variable assignment, got: {
> [WARNING]: Unable to parse /home/ubuntu/dynamic1.sh as an inventory source
> [WARNING]: No inventory was parsed, only implicit localhost is available
> { | UNREACHABLE! => {
>     "changed": false,
>     "msg": "Failed to connect to the host via ssh: ssh: Could not resolve 
> hostname {: Temporary failure in name resolution",
>     "unreachable": true
> }
> 
> 
> Ansible still doesn't accept the dynamic script's output. Ansible cli will 
> accept the file output being used with or
> without the last "," so it's odd for me. I'm supplying the list of hosts in a 
> format that Ansible will run against based
> on the file (output of the script), but ansible won't take the same output 
> from the script.
> 
> 
> 
> On Tuesday, 3 November 2020 at 09:37:11 UTC [email protected] wrote:
> 
>     On Tue, 3 Nov 2020 01:07:29 -0800 (PST)
>     "[email protected]" <[email protected]> wrote:
> 
>     > {
>     > "all": {
>     > "hosts": {
>     > "ip-172-31-39-30.eu-west-1.compute.internal": null,
>     > "ip-172-31-44-224.eu-west-1.compute.internal": null,
>     > "ip-172-31-42-6.eu-west-1.compute.internal": null,
>     > "ip-172-31-32-68.eu-west-1.compute.internal": null,
>     > }
>     > }
>     > }
>     > ...
>     > Expecting property name enclosed in double quotes: line 8 column 5 (char
>     > 242)
>     > [WARNING]: * Failed to parse /home/ubuntu/dynamic1.sh with ini plugin:
>     > /home/ubuntu/dynamic1.sh:2: Expected key=value host variable assignment,
>     > got: {
> 
>     It's wrong JSON syntax. Remove the comma at the end of line 7.
> 
>     -- 
>     Vladimir Botka
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3eabca68-7bce-43eb-ac7e-0fd7d1a13e1cn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/3eabca68-7bce-43eb-ac7e-0fd7d1a13e1cn%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/744e7abf-935a-07f0-03bd-d2638a449a44%40linuxia.de.

Attachment: OpenPGP_0x5B93015BFA2720F8.asc
Description: application/pgp-keys

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to