Ansible - 删除CentOS 6中的登录窗口

问题描述 投票:1回答:1

我为CentOS工作站写了一个加固脚本,我卡在了Cent6系统的一个过程中,我想删除登录界面,让用户输入登录ID。

这个文件是

/etc/gconf/gconf.xml.defaults/%gconf-tree.xml

这是我想编辑的一行。

<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>

我需要编辑的一行是:

value="false"

to:

value="true"

因为在这个文件里有不止一个 "disabe_user_list",我不知道如何使用 "disabe_user_list"。inlinefile 选项来编辑这个特定字段。我很肯定可能有一个regex我可以使用,但我无法弄清楚。

谁有什么好办法?

regex ansible centos centos6
1个回答
1
投票

TL;DR。

这里有一个可能的解决方案给你

- 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"

xml 模块似乎是一个比做regex更好的选择。

这可能是你的一个解决方案,但是,当然,你必须用其它的 disabe_user_list 你可能在你的文件中拥有的条目。

本攻略中的XPath认为这个条目是唯一的,基于以下事实。

  1. 这个 entry 节点名为 disable_user_list
  2. local_schema 节点下 entry 拥有 short_desc 改为 "不在登录窗口中显示已知用户"。
  3. default 节点下 local_schematype: bool

在此基础上,任务的目标是: value 属性,并将其设置为 true.

考虑到这一战术手册

- 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"

下面是一个执行的例子

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>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.