inventory inside play

19 views
Skip to first unread message

j..r..

unread,
Feb 18, 2021, 1:45:42 PM2/18/21
to Ansible Project
I'm trying to deploy vms from template on esx with vmware_guest module and this work great, but I would like to do inside this playbook some modification on vm after deployment. My inventory file is being populated with the same playbook with hosts that are being deployed, but after that I'm doing some modification, problem is that this hosts are being skipped because ansible doesn't know for this hosts, setup module doesn't do the job. How would I convinced ansible to reread inventory file?

Hear is last part of the playbook:

   - name: add to inventoryfile
     lineinfile:
       dest: /home/ansible/vmware/inventory
       line: '{{ item.vm_name }}'
     loop: '{{ vm }}'
     delegate_to: localhost

   - setup: 

    - name: Read device information
     community.general.parted: device=/dev/sda unit=MiB
     register: sda_info
     when: inventory_hostname in groups.deploy

   - name: Extend an existing partition to fill all available space
     community.general.parted:
       device: /dev/sda
       number: "{{ sda_info.partitions | length }}"
       part_end: "100%"
       resize: true
       state: present
     when: inventory_hostname in groups.deploy

   - name: pv resize
     community.general.lvg:
       vg: vg_root
        pvs: /dev/sda2
       pvresize: yes
     when: inventory_hostname in groups.deploy

   - name: fqdn
     hostname:
       name: "{{ ansible_fqdn }}"
     when: inventory_hostname in groups.deploy


Thanks

Dick Visser

unread,
Feb 18, 2021, 2:07:13 PM2/18/21
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d5833332-ea28-447f-b252-09c10c1af7e0n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Jean-Yves LENHOF

unread,
Feb 18, 2021, 2:50:38 PM2/18/21
to ansible...@googlegroups.com

j..r..

unread,
Feb 19, 2021, 12:50:09 PM2/19/21
to Ansible Project
Thanks

meta: refresh_inventory  doesn't work inside vmware_guest module, I have to do  separate tasks directive for the configuration of vm's after deployment  in the playbook

Dick Visser

unread,
Feb 19, 2021, 1:10:10 PM2/19/21
to ansible...@googlegroups.com
I think that is how it is supposed to work...

j..r..

unread,
Feb 19, 2021, 1:44:54 PM2/19/21
to Ansible Project
it  thought that  should works something like this, for example:
- hosts: all
  vars_files:
  tasks:
     -  name: create the VM
        vmware_guest:
     ...
     - name: add to /etc/hosts file
     - name: Refresh inventory
      
meta: refresh_inventory
    - name: change something1 on new vm's
    - name: change something2 on new vm's

but it doesn't


this works:

- hosts: all
  vars_files:
 tasks:
    -  name: create the VM
       vmware_guest:
     ...
    - name: add to /etc/hosts file

- name: reconfigure other stuff
 hosts: deploy
 tasks:
   - name: Refresh inventory
   
meta: refresh_inventory
  - name: change something1 on new vm's
  - name: change something2 on new vm's
Reply all
Reply to author
Forward
0 new messages