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/20220505001352.04f68dac%40gmail.com.
pgp5nsXGBiFlz.pgp
Description: OpenPGP digital signature
