Plybook with community.vmware modules & inventory item issue

२७ भ्यु
नपढिएको पहिलो सन्देशमा जानुहोस्

esxi...@gmail.com

नपढिएको,
२०२१ मार्च ६, ०२:५३:५४२१/३/६
प्रापक Ansible Project
Hi

I am using community.vmware related modules in a playbook .. which updates tags & reboot vms

In the same vm i would like to patch the VM

Below is the code .. but the yum module here seems not acting on the target ie "{{ vm_name }" but does not the ansible control node itself

Any suggestions Please ( My requirement is not to use separate playbook )

---
- hosts: localhost
  gather_facts: false
  connection: local
  vars_files:
    - /etc/ansible/playbooks/vm-provision/vars/vc.yml
  tasks:
    - name: Update tags
      community.vmware.vmware_guest_custom_attributes:
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: no
        name: "{{ vm_name }"
        state: present
        attributes:
          - name: OS
            value: "{{ vcenter_OS }}"
          - name: Location
            value: "{{ vcenter_Location }}"
    - name: upgrade all packages
      yum: name=* state=latest
     
    - name: Reboot the VM
      community.vmware.vmware_guest_powerstate:
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: no
        folder: "{{ vcenter_folder }}"
        name: "{{ vm_name }"
        state: reboot-guest

Thanks
Kiran

Jorge Rúa

नपढिएको,
२०२१ मार्च ६, ०८:०६:४८२१/३/६
प्रापक ansible...@googlegroups.com
You should modify your hosts entry to point to inventory vms and delegate to localhost vmware tasks.

Hope that helps,

Regards



 

--
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/45726bf6-d0df-4b05-bc4a-6a33358f92een%40googlegroups.com.

esxi...@gmail.com

नपढिएको,
२०२१ मार्च ६, १५:२०:१०२१/३/६
प्रापक Ansible Project
Thanks for the reply .. So you mean change below


---
- hosts: localhost
  gather_facts: false
  connection: local

to

---
- hosts: New-VM-Section
  gather_facts: false
  connection: local

AND

add in task below

- name: Update tags  &   - name: Reboot the VM
..
..
delegate_to: localhost

Jorge Rúa

नपढिएको,
२०२१ मार्च ६, १५:२७:५७२१/३/६
प्रापक ansible...@googlegroups.com
Yep, that should do the trick.

esxi...@gmail.com

नपढिएको,
२०२१ मार्च ६, १८:५०:४८२१/३/६
प्रापक Ansible Project

Thanks Again


Is below possible in this case :-

Section called New-VM-Section has many servers

But i would like playbook task of  patching only on specific vm ?


eg

[ New-VM-Section]
vm1
vm2
vm3


And the playbook below to run only on  say vm3 & not entire section called New-VM-Section

- hosts: New-VM-Section
  gather_facts: false
...
yum:..




I know below

To exclude host1 and host2 from execution and allow execution only in host3:

$ ansible-playbook --limit '!hoost1:!host2:host3' yourPlaybook.yml


Is there way to rather "include" only 1 ...

Also how to add this in playbook itself


Any suggestions Please

esxi...@gmail.com

नपढिएको,
२०२१ मार्च ६, १८:५६:०४२१/३/६
प्रापक Ansible Project
सबैलाई जवाफ पठाउनुहोस्
लेखकलाई जवाफ
फर्वार्ड गर्नुहोस्
0 नयाँ म्यासेजहरू