Ansible Dynamic Inventory Contribution

Hi all, I just written and push simple script to use as ansible dynamic inventory connected to your opennebula cloud.

Sources here:

It automatically loads your running VMs from cloud and group they by Labels. You can run ansible playbooks on this dynamic observed hosts.



Hi Kristian, I need to set hostnames automatically for VMs provisioned through opennebula. I believe above script can help me, but i am not sure how to use it as i am new for dev-ops tools . can you guide more how can i achieve expected results.

Hi, I don’t understand what you want to do. Thi script is for ansible dynamic inventory - it don’t provision any VMs, it just read VMs from API and group by Labels. So you can run ansible playbooks on specific VMs.

I also plan to write opennebula module for ansible, for provisioning VMs, but it is not in near future.

I am provisioning VMs through opennebula, but the provisioned VM hostname is always localhost.localdomain. I need to set hostname of newly provisioned VM automatically.

I tried to do with ansible or puppet, since both are new for me… I am not able to do it.

Although, from ansible command “ansible -m shell -a ‘hostname test1’” it can be done, but that is manual task… I need to automate either during provisioning of VM through webUI of opennebula by additing script or after that using ansible/puppet.

I had tried below link also, but this will do everything as expected ( update /etc/hosts file, puppet client and master config, cert auto register), but hostname is not getting change in this method also.

Can you please help it

So you can add custom var to VM template SET_HOSTNAME and opennebula contexualization script read it and sets it.

Can you share a complete example, as i used to provision VM through wizard only. refer to attach snippet, which i am using.

Replace NODE_NAME by SET_HOSTNAME and use just latest version

Thanks for quick support… It worked.

welcome :slight_smile: sometimes you just need to read source code of context scripts :slight_smile:

Thanks … where I can find all possible variable…which can be used?

look into linked github repo and source code.

Here are scripts which start on system boot

you can also write your own.

Thanks… I am trying to learn Ansible/Puppet, to automate product deployments and management. Do we have any Orchestration tool with gui or WebUI ? ( :frowning: i dont have scripting skills)

Ansible Tower, but cost is very high. You should learn at least basics.

Hello Kristian,

Sorry for my english.

I’m not pretty sure how to use your script. Did you write some tuttorial to use it ?

Did your script works with vonecloud?

Thank you very much

Hi all, this script is just dynamic hosts inventory, so you can instead of defining fixed hosts inventory in hosts file, use this script and load running VMs by labels a run ansible on them. If you need use ansible to deploy new VMs, them you need look into Ansible Modules Index -> Cloud -> Opennebula

Hi !

I understood the script purpose but I wonder how to use it.

Do I have to install something in my vonecloud vm or should I use another server ? I’m not familiard with code so I need a little explanation to start use it.

thank you very much

Hello, everything is in ansible documentation. You just call my script in ansible command by -i flag. You should also read quick start guide of ansible.

Thanks, i will try :slight_smile:

Hi everyone,

I’m having trouble to use this script. I thkink I’m missing some prerequisites.

what software should I install on my server ?

When I excute the one-inv script I have an error : /usr/local/bin/node bad interpreter no such file or directory

If someone can guide me to run it successfully .

Thank you