Thanks for the reply Abhi
What i noticed is it does update the file if there is no entry like blow is
the o/p
TASK [Update the Inventory]
*********************************************************************************************************************************************************
changed: [localhost] => (item=xx)
but if the entry already present in more than 1 group say .. then it does
not update the file & the output is
TASK [Update the Inventory]
*********************************************************************************************************************************************************
ok: [localhost] => (item=xxx)
So if a fresh box it is ok ( ie never had been provisioned )
On Tuesday, March 2, 2021 at 8:53:17 PM UTC-8 Abhijeet Kasurde wrote:
> Can you provide output of lineinfile ? Mine look like
>
> changed: [localhost] => (item=a) => {"ansible_loop_var": "item", "backup":
> "", "changed": true, "item": "a", "msg": "line added"}
> changed: [localhost] => (item=b) => {"ansible_loop_var": "item", "backup":
> "", "changed": true, "item": "b", "msg": "line added"}
>
> On Wed, Mar 3, 2021 at 10:14 AM [email protected] <[email protected]>
> wrote:
>
>> Hi
>>
>> I have a playbook which create the vm in vCenter
>> ---
>> - hosts: localhost
>> gather_facts: false
>> connection: local
>> vars_files:
>> - ./vars/xxx.yml
>>
>> tasks:
>>
>>
>> - name: Create VM using template
>> vmware_guest:
>> hostname: "{{ vcenter_server }}"
>> username: "{{ vcenter_user }}"
>> password: "{{ vcenter_pass }}"
>> datacenter: "{{ vcenter_datacenter }}"
>> cluster: "{{ vcenter_cluster }}"
>> template: "{{ vcenter_template }}"
>> ..
>> hostname: "{{ item }}"
>> with_items: "{{ servers }}"
>>
>>
>>
>>
>> - name: Update the Inventory
>> lineinfile:
>> dest: /etc/ansible/hosts
>> insertafter: '^\[MyServers\]'
>> line: '{{ item }}'
>> with_items: "{{ servers }}"
>> run_once: true
>>
>>
>>
>> VM create works well, Any suggestions why the the hosts file is not
>> getting updated .. above is the code
>>
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/542ded49-eab9-4fbf-8faa-2ba91bc3517en%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/542ded49-eab9-4fbf-8faa-2ba91bc3517en%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Thanks,
> Abhijeet Kasurde
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7c791d7d-fa06-4497-ac70-fe46d2558c97n%40googlegroups.com.