Ansible Dynamic Inventory Contribution

(Kristian Feldsam) #1

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.


(Amit Kumar) #2

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.

(Kristian Feldsam) #3

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.

(Amit Kumar) #4

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

(Kristian Feldsam) #5

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

(Amit Kumar) #6

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

(Kristian Feldsam) #7

Replace NODE_NAME by SET_HOSTNAME and use just latest version

(Amit Kumar) #8

Thanks for quick support… It worked.

(Kristian Feldsam) #9

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

(Amit Kumar) #10

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

(Kristian Feldsam) #11

look into linked github repo and source code.

(Kristian Feldsam) #12

Here are scripts which start on system boot

you can also write your own.

(Amit Kumar) #13

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)

(Kristian Feldsam) #14

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

(Yacine Fetouh) #15

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

(Kristian Feldsam) #16

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

(Yacine Fetouh) #17

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

(Kristian Feldsam) #18

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.

(Yacine Fetouh) #19

Thanks, i will try :slight_smile:

(Yacine Fetouh) #20

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