Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Vladimir Botka
Quoting from *lineinfile* parameter *regexp* https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html#parameter-regexp For state=present, the pattern to replace if found. Only the last line found will be replaced. Thank you! On Fri, 6 May 2022 13:54:20 -0700

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Nico Kadel-Garcia
On Fri, May 6, 2022 at 4:36 PM Tony Wong 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 c

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Todd Lewis
Assuming you only have one line for each version, it will assure that the line for any version that's marked false will be commented, and any line for a version marked true will be uncommented. Where it gets hairy is when you have more than one line for any version. In that case, the second tas

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Tony Wong
does this mean I cannot keep the old commented line? #image: graylog/graylog4.2.5 requirement is I need to have this line commented On Thu, May 5, 2022 at 9:50 PM Vladimir Botka wrote: > > shell> cat pb.yml > > - hosts: localhost > > vars: > > versions: > > 4.2.5: false > > 4

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread dulhaver via Ansible Project
On 06.05.22 14:52, Tony Wong wrote: is there docker module or I should just use shell module? I believe it's always better to use designated Modules over shell or command that said ... you may want to get familiar (or at least be aware of this list

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Tony Wong
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 wrote: >

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-06 Thread Tony Wong
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:

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Vladimir Botka
> 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*$' >

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Vladimir Botka
On Thu, 5 May 2022 19:21:47 -0700 Tony Wong wrote: > it only works for first node. When i run the playbook against 3 nodes the > 2nd and 3rd node have this > > image: graylog/graylog:4.2.5 > #image: graylog/graylog4.2.5 > image: graylog/graylog4.2.8 Quoting from *lineinfile* parameter *regexp*

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Tony Wong
I tested with another pb and it works fine on all 3 nodes --- - name: test hosts: k8s tasks: - name: test lineinfile: line: "Hello World" path: /tmp/temp2.txt create: true On Thu, May 5, 2022 at 7:22 PM Tony Wong wrote: > this is the playbook > > --- > - n

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Tony Wong
this is the playbook --- - name: test hosts: k8s vars: versions: 4.2.5: false 4.2.8: true tasks: - name: test lineinfile: path: /tmp/temp.txt regex: '^\s*#*\s*image: graylog/graylog{{ item.key }}\s*$' line: '{{ hash }}image: graylog/graylog{{

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Tony Wong
it only works for first node. When i run the playbook against 3 nodes the 2nd and 3rd node have this image: graylog/graylog:4.2.5 #image: graylog/graylog4.2.5 image: graylog/graylog4.2.8 On Thu, May 5, 2022 at 3:51 PM Vladimir Botka wrote: > On Thu, 5 May 2022 10:03:02 -0700 > Tony Wong wrote:

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Vladimir Botka
On Thu, 5 May 2022 10:03:02 -0700 Tony Wong 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 'y' is missing in 'gralog/graylog:4.2.5' in the first line. This is the reason

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Todd Lewis
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 test

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-05 Thread Tony Wong
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 wrote: > Got it, thanks! > > On Wed, May 4, 2022 at 3:13 PM Vladimir Botka wrote: > >> See the com

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-04 Thread Tony Wong
Got it, thanks! On Wed, May 4, 2022 at 3:13 PM Vladimir Botka 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: >

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-04 Thread Vladimir Botka
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.

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-04 Thread Tony Wong
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

Re: [ansible-project] playbook to comment out one line and add another line in a file

2022-05-03 Thread Vladimir Botka
On Tue, 3 May 2022 10:10:06 -0700 (PDT) Tony Wong 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/g

[ansible-project] playbook to comment out one line and add another line in a file

2022-05-03 Thread Tony Wong
how do i use ansible to remotely comment out a line in a docker-compose file and add a line like this #image: gralog/graylog:4.2.5 image: graylog/graylog4.2.8 then do a docker compose down and docker-compose up -d i need to run this on multiple nodes -- You received this message because you