Score:0

Ansible; add hosts to inventory by script

mx flag

I just started working with/learning to use Ansible.

I want to add hosts to an inventory file using a script, and I am wondering if there is a command line tool to accomplish that.

Something that looks like this;

ansible-inventory -i inventory.yml --add-host hostname --ip <ipaddress> --password <password>

I have looked through the documentation of Ansible, but I couldn't find a command that is able to change inventory files.

If there isn't a command for that, I just have to change the file itself in the script but I am not a big fan of that since I'm afraid that is prone to errors.

Score:2
in flag

No, there is no command for this. But it's just a yaml file ... there is a module to edit yaml files in the Ansible Galaxy.

Another option would be to use some kind of database. The inventory does not necessarily have to be a text file, it can also be a script that gets it's data somewhere else.

Douwe avatar
mx flag
Thanks! Do you mean this module?: https://galaxy.ansible.com/konono/easyconf
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.