vsphere_guest provisioning and add_host module : problem on dynamic inventory VS static inventory

261 views
Skip to first unread message

nicolas.w...@boulanger.com

unread,
Feb 10, 2015, 12:27:45 PM2/10/15
to ansible...@googlegroups.com
Hi Everyone,

I try to realise a playbook of autoprovisionning from scratch to "full installed application"
I use the "ansible inventory" for guide the provisionning

I use a lot of group who describe the configuration of the target: 

if the entries (hostname) is in inventory ansible group "on-vmware" : the playbook use vsphere_guest module to create the host (by cloning) on a vmware cluster :

The cloning process is OK, my vm starts on a provisionning network => dhcp and vsphere_facts give to me IP adress of the new vm ( owing to vmtools).


my playbook :
**********************************************************************************************
- name : Configure/Check Host (Infra)
  hosts: self-made                                           - --> (self-made is a group where i put the new/existing ressource to create or check configuration)
  connection: local
  sudo: false
  gather_facts: false
  serial: 1

  roles:
    - role: infra/internal/vmware/Host                      -->      this role create vmware guest by clonning and return {{ provisionning_temporary_ip }}

  post_tasks:
    - name: add_host in memory 
      local_action:
        module: add_host
        hostname: "{{ inventory_hostname }}"
        ansible_ssh_host: "{{ provisionning_temporary_ip }}"
        groups: hostsInProvisionningNetwork


- name: Configure/Check Network (OS / Infra)
  hosts: hostsInProvisionningNetwork
  gather_facts: --->                   ( when true : Error SSH can't connect at "GATHERING FACTS" step )
                                              ( when false: SSH error on first tasks who try to connect )                                   lost information of ansible_ssh_host set
 
  roles:
    - role: os/network

**********************************************************************************************



I write some "roles" that work unitarily to customise guest os network / and relocate on the good vmware network.
this role use many informations about network are stored in variables on inventory network group_vars

I can't retrieve this information : i try a lot a test but with unsucess...

I try to "add_host" dynamicaly ( with ansible_ssh_host = {{ provisionning_temporary_ip }} ) but i lost the information about the static inventory (network group_vars) that I need for my next step role.

Have you a idea or a method ?

Thx a lot ..

Giovanni Tirloni

unread,
Feb 13, 2015, 5:28:07 AM2/13/15
to ansible...@googlegroups.com
On Tue, 10 Feb 2015 09:27 -0800, nicolas.w...@boulanger.com wrote:
> roles:
> - role: infra/internal/vmware/Host --> this
> role create vmware guest by clonning and return {{
> provisionning_temporary_ip }}
>
> post_tasks:
> - name: add_host in memory
> local_action:
> module: add_host
> hostname: "{{ inventory_hostname }}"
> ansible_ssh_host: "{{ provisionning_temporary_ip }}"
> groups: hostsInProvisionningNetwork
>
>
> - name: Configure/Check Network (OS / Infra)
> hosts: hostsInProvisionningNetwork
> gather_facts: ---> ( when true : Error SSH can't
> connect at "GATHERING FACTS" step )
> ( when false: SSH error on
> first tasks who try to connect ) lost
> information of ansible_ssh_host set
>
> roles:
> - role: os/network

Personally I wouldn't do this with roles, at least not for the
provisioning phase.

I haven't worked with the vsphere_guest module yet, but my suggestion is
to have 2 plays in your playbook: first provision, add the new VM to
your group, then a second play to configure the hosts (and apply roles).

---
- name: provision servers
gather_facts: no
hosts: localhost
tasks:
- name: provision server
vsphere_guest: .....
register: new_guest

- name: show properties
debug:
var: new_guest

- name: add to group
add_host:
name: {{ name from new_guest }}
groups: provision_group

- name: configure servers
gather_facts: yes
hosts: provision_group
sudo: yes
roles: ...
tasks: ...


Giovanni
Reply all
Reply to author
Forward
0 new messages