# Hello guys, I'm unable to pass a dynamic inventory script to read a yml file from repo

**URL:** <https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369>\
**Category:** Ansible Project\
**Created:** [September 26, 2019, 4:56pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369 "2019-09-26T16:56:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bariou\_Alarou](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@Bariou\_Alarou](https://forum.ansible.com/u/Bariou_Alarou)\
**Post date:** [September 26, 2019, 4:56pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369/1 "2019-09-26T16:56:26Z")

</div>

I’m able to get the list of my hosts from the yml file when running this command

$ /opt/ansible/static/inventory/inventory.py [https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml  
{  
“\_meta”: {  
“hostvars”: {}  
},  
“db”: {  
“children”: [  
“db-site2”,  
“db-site1”  
]  
},  
“db-site1”: {  
“hosts”: [  
“[bary785c.mylabserver.com](http://bary785c.mylabserver.com)”,  
“[bary786c.mylabserver.com](http://bary786c.mylabserver.com)”  
]  
},  
“db-site2”: {  
“hosts”: [  
“[bary783c.mylabserver.com](http://bary783c.mylabserver.com)”,  
“[bary785c.mylabserver.com](http://bary785c.mylabserver.com)”  
]  
},  
“site1”: {  
“children”: [  
“staging-site1”  
]  
},  
“site2”: {  
“children”: [  
“staging-site2”  
]  
},  
“staging”: {  
“children”: [  
“web”,  
“db”  
]  
},  
“staging-db”: {  
“children”: [  
“db”  
]  
},  
“staging-db-site1”: {  
“children”: [  
“db-site1”  
]  
},  
“staging-db-site2”: {  
“children”: [  
“db-site2”  
]  
},  
“staging-site1”: {  
“children”: [  
“web-site1”,  
“db-site1”  
]  
},  
“staging-site2”: {  
“children”: [  
“web-site2”,  
“db-site2”  
]  
},  
“staging-web”: {  
“children”: [  
“web”  
]  
},  
“staging-web-site1”: {  
“children”: [  
“web-site1”  
]  
},  
“staging-web-site2”: {  
“children”: [  
“web-site2”  
]  
},  
“web”: {  
“children”: [  
“web-site2”,  
“web-site1”  
]  
},  
“web-site1”: {  
“hosts”: [  
“[bary781c.mylabserver.com](http://bary781c.mylabserver.com)”,  
“[bary782c.mylabserver.com](http://bary782c.mylabserver.com)”  
]  
},  
“web-site2”: {  
“hosts”: [  
“[bary783c.mylabserver.com](http://bary783c.mylabserver.com)”,  
“[bary784c.mylabserver.com](http://bary784c.mylabserver.com)”  
]  
}  
}

But when I’m trying now to run any ansible command to call the same file, I’m getting this error.

]$ ansible -i /opt/ansible/static/inventory/inventory.py all -m ping -e “[https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml”  
[WARNING]: \* Failed to parse /opt/ansible/static/inventory/inventory.py with script plugin: Inventory script (/opt/ansible/static/inventory/inventory.py) had an execution error: usage: inventory.py [-h] [–sshkey SSHKEY] [–commit  
COMMIT] url inventory inventory.py: error: too few arguments

[WARNING]: Unable to parse /opt/ansible/static/inventory/inventory.py 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’

Please can you help me here?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 26, 2019, 7:02pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369/2 "2019-09-26T19:02:50Z")

</div>

Extra variables (-e, --extra-vars) are passed to the play not to the dynamic  
inventory script. Create a wrapper for inventory.py with the parameters.

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Bariou\_Alarou](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@Bariou\_Alarou](https://forum.ansible.com/u/Bariou_Alarou)\
**Post date:** [September 26, 2019, 7:59pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369/3 "2019-09-26T19:59:13Z")

</div>

Thanks for your response. Where do I have to create the wrapper file? (is it in ansible.cfg) file.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 26, 2019, 8:10pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369/4 "2019-09-26T20:10:02Z")

</div>

> \> usage:  
> \> \> inventory.py [-h] [--sshkey SSHKEY] [--commit  
> \> \> COMMIT] url inventory inventory.py: error: too few arguments  
> \>  
> \> Extra variables (-e, --extra-vars) are passed to the play not to the  
> \> dynamic  
> \> inventory script. Create a wrapper for inventory.py with the parameters.
> 
> Thanks for your response. Where do I have to create the wrapper file? (is  
> it in ansible.cfg) file.

For example create a script inventory.sh.

&nbsp;&nbsp;#!/bin/sh/  
&nbsp;&nbsp;${INVPATH}/inventory.py [https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml

and use it in the command

&nbsp;&nbsp;ansible -i inventory.sh all -m ping

---

<div class="post-metadata">

**Author:** ![Bariou\_Alarou](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@Bariou\_Alarou](https://forum.ansible.com/u/Bariou_Alarou)\
**Post date:** [September 26, 2019, 8:28pm UTC](https://forum.ansible.com/t/hello-guys-im-unable-to-pass-a-dynamic-inventory-script-to-read-a-yml-file-from-repo/31369/5 "2019-09-26T20:28:05Z")

</div>

Hello boss. Here is what happened. when I use the Variable same you describe, I got an error. It seem I need to define INVPATH as variable. but I don’t know where.

[ansible@bary782c ~]$ ansible -i inventory.sh all -m ping

[WARNING]: \* Failed to parse /home/ansible/inventory.sh with script plugin: Inventory script (/home/ansible/inventory.sh) had an execution error: /home/ansible/inventory.sh: line 4: ${ INVPATH}/inventory.py: bad substitution

[WARNING]: Unable to parse /home/ansible/inventory.sh 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’

and this the script

#!/bin/bash

${ INVPATH}/inventory.py [https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml

as you gave me. But when I comment out that line and specified all the path in the script like this

#!/bin/bash

/opt/ansible/static/inventory/inventory.py [https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml

#${ INVPATH}/inventory.py [https://github.com/adeyeri88/test.git](https://github.com/adeyeri88/test.git) staging.yml

AND now run the the ansible command as you suggest it works

[ansible@bary782c ~]$ ansible -i inventory.sh all -m ping  
[DEPRECATION WARNING]: The TRANSFORM\_INVALID\_GROUP\_CHARS settings is set to allow bad characters in group names by default, this will change, but still be user configurable on deprecation. This feature will be removed in version 2.10.  
Deprecation warnings can be disabled by setting deprecation\_warnings=False in ansible.cfg.  
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

[bary782c.mylabserver.com](http://bary782c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}  
[bary786c.mylabserver.com](http://bary786c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}  
[bary783c.mylabserver.com](http://bary783c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}  
[bary781c.mylabserver.com](http://bary781c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}  
[bary785c.mylabserver.com](http://bary785c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}  
[bary784c.mylabserver.com](http://bary784c.mylabserver.com) | SUCCESS =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“ping”: “pong”  
}
