# removing a domain form sssd.conf

**URL:** <https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592>\
**Category:** Ansible Project\
**Created:** [February 1, 2019, 1:22pm UTC](https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592 "2019-02-01T13:22:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lewis\_Carroll](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@Lewis\_Carroll](https://forum.ansible.com/u/Lewis_Carroll)\
**Post date:** [February 1, 2019, 1:22pm UTC](https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592/1 "2019-02-01T13:22:58Z")

</div>

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]’. But instead it pretty much deletes the whole file. 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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 1, 2019, 3:11pm UTC](https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592/2 "2019-02-01T15:11:48Z")

</div>

> 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]
> 
> > ...
> 
> &nbsp;&nbsp;I tried this:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- replace:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: '/home/admin/sssd.conf'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: '.\*'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;before: '[sssd]'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- replace:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /home/admin/sssd.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: '(?s)\[domain/example\].\*?^$'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup: yes

---

<div class="post-metadata">

**Author:** ![Lewis\_Carroll](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@Lewis\_Carroll](https://forum.ansible.com/u/Lewis_Carroll)\
**Post date:** [February 1, 2019, 3:57pm UTC](https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592/3 "2019-02-01T15:57:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [February 2, 2019, 1:33am UTC](https://forum.ansible.com/t/removing-a-domain-form-sssd-conf/29592/4 "2019-02-02T01:33:13Z")

</div>

Or you could use the ini\_file module to remove the section.
