do ytou mean like this

---
- name: change file add line
  hosts: k8s

  versions:
    4.2.5: false
    4.2.8: true

  tasks:
    - name: change file add line
      lineinfile:
        regex: '^\s*#*\s*image: graylog/graylog{{ item.key }}\s*$'
        line: '{{ hash }}image: graylog/graylog{{ item.key }}'
        path: /tmp/temp.txt
      loop:
        vars:
          hash: "{{ item.value|ternary('', '#') }}"




On Tue, May 3, 2022 at 11:52 AM Vladimir Botka <[email protected]> wrote:

> On Tue, 3 May 2022 10:10:06 -0700 (PDT)
> Tony Wong <[email protected]> wrote:
>
> > comment out a line in a docker-compose
> > file and add a line
> >
> > #image: gralog/graylog:4.2.5
> > image: graylog/graylog4.2.8
>
> I assume, the expected result is below. If not confirm your example
> and ignore the rest here
>
> #image: graylog/graylog4.2.5
> image: graylog/graylog4.2.8
>
> For example, create a dictionary of the disabled and enabled versions
>
>     versions:
>       4.2.5: false
>       4.2.8: true
>
> Then the *lineinfile* task below should comment out disabled versions
> and add enabled versions
>
>     - 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('', '#') }}"
>
> --
> 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/CALmkhkqOFcPjdb2snDU%2BR1-ErGz2cULxGZt9u3Sy5-o_u84XfA%40mail.gmail.com.

Reply via email to