Hi,

Another way of doing...

You can also change the inventory live with some modules

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/group_by_module.html#ansible-collections-ansible-builtin-group-by-module

Regards,

JYL


Le 18/02/2021 à 19:45, j..r.. a écrit :
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

--
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-project+unsubscr...@googlegroups.com <mailto:ansible-project+unsubscr...@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 <https://groups.google.com/d/msgid/ansible-project/d5833332-ea28-447f-b252-09c10c1af7e0n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cb0301e8-2750-bf66-13d4-021a7ca93083%40lenhof.eu.org.

Reply via email to