On Fri, May 6, 2022 at 4:36 PM Tony Wong <[email protected]> wrote:
>
> does this mean I cannot keep the old commented line?
>
> #image: graylog/graylog4.2.5

It's tricky. You can write scripting to do anything you want to do,
but it's not necessarily built-in precisely the way you want it to
behave.

It's why many config files, such as those in /etc/sudoers.d/, deploy
files rather than editing lines of /etc/sudoers.

> requirement is I need to have this line commented
>
> On Thu, May 5, 2022 at 9:50 PM Vladimir Botka <[email protected]> wrote:
>>
>> > shell> cat pb.yml
>> > - hosts: localhost
>> >   vars:
>> >     versions:
>> >       4.2.5: false
>> >       4.2.8: true
>> >   tasks:
>> >     - name: Remove versions
>> >       lineinfile:
>> >         state: absent
>> >         path: docker-compose
>> >         regexp: '^\s*#*\s*image: graylog/graylog{{ item.key }}\s*$'
>> >       loop: "{{ versions|dict2items }}"
>> >       when: force_remove_versions|d(false)|bool
>> >     - name: Add versions
>> >       lineinfile:
>> >         path: docker-compose
>> >         regexp: '^\s*#*\s*image: graylog/graylog{{ item.key }}\s*$'
>> >         line: '{{ hash }}image: graylog/graylog{{ item.key }}'
>> >       loop: "{{ versions|dict2items }}"
>> >       vars:
>> >         hash: "{{ item.value|ternary('', '#') }}"
>>
>> The playbook is idempotent
>>
>> shell> cat docker-compose
>> #image: graylog/graylog4.2.5
>> image: graylog/graylog4.2.8
>>
>>
>> shell> ansible-playbook pb.yml
>>
>> PLAY [localhost]
>> ****************************************************************
>>
>> TASK [Remove versions]
>> ****************************************************************
>> skipping: [localhost] => (item={'key': '4.2.5', 'value': False})
>> skipping: [localhost] => (item={'key': '4.2.8', 'value': True})
>>
>> TASK [Add versions]
>> ****************************************************************
>> ok: [localhost] => (item={'key': '4.2.5', 'value': False})
>> ok: [localhost] => (item={'key': '4.2.8', 'value': True})
>>
>> PLAY RECAP
>> ****************************************************************
>> localhost: ok=1    changed=0    unreachable=0
>> failed=0    skipped=1    rescued=0    ignored=0
>>
>>
>> --
>> 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/CALmkhkpKHPEZ7YjVKhS8EmnxyJVJJ%2BGggtKuHEqNXKasznDpDg%40mail.gmail.com.

-- 
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/CAOCN9rxwVBZSL5_pi_QmEY9%3DXQMQ-CdEfYBKoAcToqwH8YjtnQ%40mail.gmail.com.

Reply via email to