Nice. I new I was missing something. I went with the second option. It 
replaced all the text with a blank line. The former left a blank line for 
each match.

On Friday, February 1, 2019 at 9:11:59 AM UTC-6, Kai Stian Olstad wrote:
>
> On 01.02.2019 14:22, Lewis Carroll wrote: 
> > I am trying to figure out how to use replace or lineinfile to remove a 
> > domain entry in sssd.conf. Here is example: 
> > 
> > [domain/example] 
> >> cache_credentials = false 
> >> enumerate = true 
> >> ldap_schema = rfc2307 
> >> ldap_rfc2307_fallback_to_local_users = true 
> >> ldap_search_base = dc=example,dc=com 
> >> id_provider = ldap 
> >> auth_provider = ldap 
> >> chpass_provider = ldap 
> >> sudo_provider = ldap 
> >> ldap_uri = ldaps://ldap1.example.com:636, 
> >> ldaps://ldap2.example.com:636, 
> >> ldaps://ldap3.example.com:636 
> >> ldap_chpass_uri = ldaps://ldap1.example.com:636 
> >> ldap_tls_reqcert = allow 
> >> access_provider = simple 
> >> simple_allow_groups = example_admins 
> >> 
> > 
> > 
> > [sssd] 
> >> ... 
> > 
> > 
> >   I tried this: 
> > 
> > 
> >>      - replace: 
> >>         path: '/home/admin/sssd.conf' 
> >>         regexp: '.*' 
> >>         before: '[sssd]' 
> >>         backup: yes 
> > 
> > 
> > My thought is that this would remove every line before '[sssd]'. 
>
> The before is also regexp so you need to escape the [] too. 
> If you do that it will delete everything from the start of the file to 
> the [sssd] 
>
>
> > But instead it pretty much deletes the whole file. 
>
> Since it can't find [sssd] because of the missing escape it will remove 
> the content of every line. 
>
>
> > I have a workaround using 
> > sed via the command module. But I'd like to use replace or lineinfile. 
> > Any 
> > ideas? I also figured I could use a loop of regexps. Just seem like 
> > this 
> > should be simple. Heck the sed is simple for this. 
> > 
> > sed -i '/^\[domain\/example\]/,/^$/d' /etc/sssd/sssd.conf 
>
> This one will work more or less like you sed 
>
>      - replace: 
>          path: /home/admin/sssd.conf 
>          regexp: '(?s)\[domain/example\].*?^$' 
>          backup: yes 
>
> -- 
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fe0ec39d-b0fb-4a98-80be-578db35844f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to