for eg 


[group1]
server1
server2
[group2]
server1
server2 


if you remove from group one & run does not update .... So lineinfile 
should have someway to say the position exactly below [group1] add is 
missing ... 

On Tuesday, March 2, 2021 at 11:08:50 PM UTC-8 [email protected] wrote:

> 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/aa2c99d0-c81c-4ccb-8952-8b4ef61ae7f3n%40googlegroups.com.

Reply via email to