I have another requirement to down the container on node01 first

docker-compose down
then run the pb,
then docker-compose up -d

wait 30secs or so

repeat with node02
repeat with node03

is there docker module or I should just use shell module?


On Fri, May 6, 2022 at 5:48 AM Tony Wong <[email protected]> wrote:

> i got it to work the simple way with multiple tasks
>
> ---
> - name: test
>   hosts: k8s
>
>   tasks:
>     - name: comment line
>       lineinfile:
>         line: "#image: graylog/graylog4.2.5"
>         regexp: '^image:\sgraylog/graylog4.2.5'
>         path: /tmp/temp2.txt
>     - name: add line
>       lineinfile:
>         line: "image: graylog/graylog4.2.8"
>         path: /tmp/temp2.txt
>         create: true
>
>
> probably not the most efficient.
>
> 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/CALmkhkrz037P9wJyeUL7%3DmuSLzpbD_CA_cit%3DjF%3DAnvUxF%3Dcyg%40mail.gmail.com.

Reply via email to