TL;DR;
Here is a possible solution for you
- xml:
path: /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
xpath: "/entry[@name='disable_user_list']/local_schema[@short_desc='Do not show known users in the login window']/default[@type='bool']"
attribute: value
value: "true"
The xml module seems to be a better alternative than doing a regex.
This could be a solution for you, but, of course, you'll have to validate this with the other disabe_user_list entries that you might have in your file.
The XPath in this playbook consider that this entry is unique based on the facts that:
- the
entry node is named disable_user_list
- the
local_schema node under entry have a short_desc reading `Do not show known users in the login window``
- the
default node under local_schema is of type: bool
Based on that, the task would target the value attribute and set it to true.
Given this playbook
- hosts: local
gather_facts: no
tasks:
- xml:
path: /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
xpath: "/entry[@name='disable_user_list']/local_schema[@short_desc='Do not show known users in the login window']/default[@type='bool']"
attribute: value
value: "true"
Here is an example of execution
cat /etc/gconf/gconf.xml.defaults/%gconf-tree.xml && ansible-playbook play.yml && cat /etc/gconf/gconf.xml.defaults/\%gconf-tree.xml
<?xml version='1.0' encoding='UTF-8'?>
<entry name="disable_user_list" mtime="1558109430" type="schema" stype="bool" owner="gdm-simple-greeter" gettext_domain="gdm">
<local_schema locale="C" short_desc="Do not show known users in the login window">
<default type="bool" value="false"/>
<longdesc>Set to true to disable showing known users in the login window.</longdesc>
</local_schema>
</entry>
PLAY [local] ***********************************************************************************************************************************************************************************************
TASK [xml] *************************************************************************************************************************************************************************************************
changed: [local]
PLAY RECAP *************************************************************************************************************************************************************************************************
local : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
<?xml version='1.0' encoding='UTF-8'?>
<entry name="disable_user_list" mtime="1558109430" type="schema" stype="bool" owner="gdm-simple-greeter" gettext_domain="gdm">
<local_schema locale="C" short_desc="Do not show known users in the login window">
<default type="bool" value="true"/>
<longdesc>Set to true to disable showing known users in the login window.</longdesc>
</local_schema>
</entry>