I don't think you can get `line_in_file` to do what you want. 
`line_in_file` is designed to operate on a single line. Keeping the 
commented out line greatly complicates matters. How many patchlevels to you 
intend to maintain as comments?

You may be able to do it with `replace` and a lot of testing. But I'd 
strongly encourage you to reconsider using `#` as a poor replacement for 
revision control.

On Thursday, May 5, 2022 at 1:03:30 PM UTC-4 [email protected] wrote:

>
> I was abl to get my first node changed but the other 2 had this added
>
> image: gralog/graylog:4.2.5
> #image: graylog/graylog4.2.5
> image: graylog/graylog4.2.8
>
> On Wed, May 4, 2022 at 7:09 PM Tony Wong <[email protected]> wrote:
>
>> Got it, thanks! 
>>
>> On Wed, May 4, 2022 at 3:13 PM Vladimir Botka <[email protected]> wrote:
>>
>>> See the complete example below
>>>
>>> shell> cat docker-compose
>>> image: graylog/graylog4.2.5
>>>
>>>
>>> shell> cat pb.yml
>>> ---
>>> - hosts: localhost
>>>   vars:
>>>     versions:
>>>       4.2.5: false
>>>       4.2.8: true
>>>   tasks:
>>>     - lineinfile:
>>>         path: docker-compose
>>>         regex: '^\s*#*\s*image: graylog/graylog{{ item.key }}\s*$'
>>>         line: '{{ hash }}image: graylog/graylog{{ item.key }}'
>>>       loop: "{{ versions|dict2items }}"
>>>       vars:
>>>         hash: "{{ item.value|ternary('', '#') }}"
>>>
>>>
>>> shell> ansible-playbook pb.yml
>>>
>>> PLAY [localhost]
>>> ***************************************************************
>>>
>>> TASK [lineinfile]
>>> ***************************************************************
>>> changed: [localhost] => (item={'key': '4.2.5', 'value': False})
>>> changed: [localhost] => (item={'key': '4.2.8', 'value': True})
>>>
>>> PLAY RECAP
>>> ***************************************************************
>>> localhost: ok=1    changed=1    unreachable=0
>>> failed=0    skipped=0    rescued=0    ignored=0   
>>>
>>>
>>> shell> cat docker-compose
>>> #image: graylog/graylog4.2.5
>>> image: graylog/graylog4.2.8
>>>
>>>
>>> -- 
>>> Vladimir Botka
>>>
>>

-- 
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/da2f1479-c114-40c0-a329-2e9dea9a267cn%40googlegroups.com.

Reply via email to