OpenStack - Try to add new hosts in a dynamic inventory file

40 views
Skip to first unread message

Soufiane Benmalek

unread,
Apr 11, 2017, 11:32:41 AM4/11/17
to Ansible Project
Hi,

I use Ansible to launch new servers on an OpenStack public cloud provider.
This is my playbook:

---
- name: launch an instance
  hosts: localhost
  gather_facts: false
  tasks:
  - name: launch an instance
    os_server:
         state: present
         auth:
           auth_url: https://auth.cloud.ovh.net/v2.0/
           username:  secret
           password: secret
           project_name: secret
         region_name: SBG3
         name: mariadbserver-01
         image: CentOS 7
         state: present
         network: Ext-Net
         flavor: s1-2
         key_name: DBaaSOVHKey
         meta:
            hostname: mariadb
    register: newnode

  - name: Show Server's IP
    debug: var=item
           with_items: openstack.instances
#newnode.openstack.public_v4 

  - name: Register the hosts in the inventory
    add_host:
      name: "{{ newnode.openstack.public_v4 }}"
      group: "{{mariadbservers}}"

Error:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'mariadbservers' is undefined\n\nThe error appears to have been in '/home/soufiane/DBaaS/ansible-role-dbaas/roles/novaserver/tasks/main.yml': line 28, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: Register the hosts in the inventory\n    ^ here\n"}


Problem:

Nothing is added

Any ideas

i want in /etc/ansible/hosts

[mariadbservers]
x.x.x.x


Kai Stian Olstad

unread,
Apr 18, 2017, 11:58:27 AM4/18/17
to ansible...@googlegroups.com
The reason is in the error message "The error was: 'mariadbservers' is
undefined"

Your group: should not be a variable, but name of the group that you
would like to add the host in.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages