Re: [ansible-project] lineinfile anywhere match

2017-06-02 Thread Anfield
Ah I didnt see the bit at the bottom. Thanks


>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bb104894-cd32-4863-9fc2-c151c3ce1e5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lineinfile anywhere match

2017-06-02 Thread Kai Stian Olstad

On 02. juni 2017 18:54, Anfield wrote:

Ive read both. Its still not clear to me how to do an anywhere match on a
string


OK, but did you read my entire answer?
The answer to your question is in it.


--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/34369ac4-9241-95f4-f3cd-a21d3781f768%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lineinfile anywhere match

2017-06-02 Thread Anfield


Found the answer, from the below list, purple replaced brown with the 
> playbook further below



crimson
blahstuffcans
buns
buns
grey
purple
orange
grey
grey
%jabba%
jabba1
 

Below replaced brown with purple for example

---
- hosts: local
  tasks:
- name: Line In File
  lineinfile:
dest: /home/ansible/test.txt
regexp: 'row'
insertbefore: BOF
line: 'purple'
state: present
  register: foundstuff
- debug: var=foundstuff
 

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8d0f0de4-40df-4d0d-8e1a-1e0c626f21d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lineinfile anywhere match

2017-06-02 Thread Anfield
Ive read both. Its still not clear to me how to do an anywhere match on a 
string


>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/476115fd-b41f-4962-97a3-4ad8d32a2e8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lineinfile anywhere match

2017-06-02 Thread Kai Stian Olstad

On 02. juni 2017 17:55, Anfield wrote:

How do I do an anywhere match for a string and replace with some text?

The below playbook doesnt work. But just looking for example to search for
part of green - reen and replace this with jabba.

How do I do that? Thanks


I suggest reading about regexp here
https://docs.python.org/2/library/re.html
and then
https://docs.ansible.com/ansible/lineinfile_module.html



List


red
blahstuffcans
buns
buns
grey
green
brown
red
grey
grey



Playbook -

---
- hosts: local
   tasks:
 - name: Line In File
   lineinfile:
 dest: /home/ansible/test.txt
 regexp: '%reen%'
 line: '%jabba%'
   register: foundstuff
 - debug: var=foundstuff


% is not a valid regexp special character so you literally searching for 
a line containing %reen% and replace that line with %jabba%.

But since %reen% is not in file it will add %jabba% to the bottom.

To make it work you need to do this

  - name: Line In File
lineinfile:
  dest: /home/ansible/test.txt
  backrefs: yes
  regexp: '(.*)reen(.*)'
  line: '\1jabba\2'

--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4cec57d9-2a38-0a88-6681-92c2e8e60237%40olstad.com.
For more options, visit https://groups.google.com/d/optout.