Ansible Dynamic Inventory Contribution

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

Hi, you need nodejs installed in /usr/local/bin/node and npm.

Hi all, I updated this tool, there are few small fixes and how to use guide was added!

Hi @feldsam… I am following the steps mentioned above, but getting following message.

Blockquote
[amit@ansible-controller ansible-one-inv-1.0.1]$ npm install
ansible-one-inv@1.0.0 /home/amit/ansible/dynamic/ansible-one-inv-1.0.1
├── commander@2.20.0
└─┬ opennebula@1.0.12
├─┬ xml2js@0.4.4
│ ├── sax@0.6.1
│ └── xmlbuilder@13.0.2
└─┬ xmlrpc@1.0.2
├── sax@0.4.3
└── xmlbuilder@0.3.1

npm WARN ansible-one-inv@1.0.0 No repository field.

[amit@ansible-controller ansible-one-inv-1.0.1]$ ./one-inv --list
-bash: ./one-inv: /usr/local/bin/node: bad interpreter: No such file or directory

Blockquote

please suggest.

you dont have nodejs installed in /usr/local/bin/node

Thanks. It is working now.

nodejs were installed but executable were in different directly, as i am usig CentOS… I just created soft link for path suggested by you.

Blockquote

/usr/local/bin/node

Blockquote

Hi Kristian,

I am using Ansible 2.8 and Opennebula 5.8 along with dynamic inventory. is there any way to provide one_vm paramters as Variable & Prompt while executing playbook ?

Intention is to provide “labels” as input through vars_prompt and dynamic inventory will pick that label. and change in playbook for every execution can be avoided.

please suggest

Regards,
Amit K

Hi,

It is resolved… Thanks for your support.

Regards,
Amit Kumar

hi, would you share your solution? Can be handy for others

Definately…

Objective: Provision VM ( CentOS or Ubuntu as per user selection ) using command line option and install software (apache or mysql as per user selection ) over it using Ansible playbook with the use of dynamic inventory.

How to: Use dynamic inventory by following Kristian Feldsam recommandation. -> Create 1st playbook with following content

- name: provision VM
  one_vm:
    api_username: XXXX
    api_password: XXXX
    api_url: http://192.X.X.X:2633/RPC2
    template_id: 3
    labels: "{{ mylabel }}"
    attributes:
      name: "{{ hostname }}"
  register: vm
- debug:
    msg: "{{ vm.instances[0].networks[0].ip }}"
- wait_for_connection:
  delegate_to: '{{ vm.instances[0].networks[0].ip }}'

Above task will provision VM from cmd line
ansible-playbook -i /etc/ansible/pcloud /home/XXX/ansible/vmbuild1.yml -e “mylabel=web hostname=host1” … This gives me flexibility to provide hostname at cmdline itself. and output of playbook will show me IP of new machine along with setup of label.

Next playbook will is pretty straight, it will use IP received from 1st output
ansible-playbook -i /etc/ansible/one-inv -l 192.X.X.X /home/XXX/ansible/swinstall.yml.

Next Objective: Finding out way to combine both playbooks, so that single command will provision and install the software. It should be registering the new build VM IP of 1st playbook and use that for 2nd playbook as source.

Thanks & Regards,
Amit K

Hi, thanks for sharing. In this case, I think, that dynamic invertory is useless, when you want limit to one instance only by the IP.

Look at this

there is part, where newly created instance is added to host groups on fly

Hello all, I just rewrited this script to python. Actual sources are online in the same repo and you can use it in you ansible project.

One new feature: host group All where sits all hosts
^ @nimbus-tech

@mabdou can we add this to opennebula addons?

Hello @feldsam,

More than being an Add-on within our OpenNebula catalog, this would be more useful being included as part of the Official Playbooks of Ansible. This is a specific functionality that would best be outlined here - https://github.com/ansible/ansible/tree/devel/contrib/inventory/. Would you be willing to make this contribution there?

Best,
Michael

Hello @mabdou, Ansible PR. I had to rewrite it again, because Ansible uses inventory plugins now (inventory scripts are deprecated and no more new contribution can be done)

2 Likes

That sounds great, thank you! :+1: Keep us posted about that plugin, please.