2016-02-04 37 views
1

我想修改一個centos firewalld區域文件使用augeas和xml鏡頭。修改centos firewalld區域文件與augeas失去縮進

默認的公共區域文件看起來像:

<?xml version="1.0" encoding="utf-8"?> 
<zone> 
    <short>Public</short> 
    <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> 
    <service name="dhcpv6-client"/> 
    <service name="ssh"/> 
</zone> 

,如果我加載到augtool我得到如下:

# augtool --noload --noautoload --echo 
augtool> set /augeas/load/xml/lens "Xml.lns" 
augtool> set /augeas/load/xml/incl "/etc/firewalld/zones/public.xml" 
augtool> load 
augtool> print /files/etc/firewalld/zones/public.xml 
/files/etc/firewalld/zones/public.xml 
/files/etc/firewalld/zones/public.xml/#declaration 
/files/etc/firewalld/zones/public.xml/#declaration/#attribute 
/files/etc/firewalld/zones/public.xml/#declaration/#attribute/version = "1.0" 
/files/etc/firewalld/zones/public.xml/#declaration/#attribute/encoding = "utf-8" 
/files/etc/firewalld/zones/public.xml/zone 
/files/etc/firewalld/zones/public.xml/zone/#text[1] = "\n " 
/files/etc/firewalld/zones/public.xml/zone/short 
/files/etc/firewalld/zones/public.xml/zone/short/#text = "Public" 
/files/etc/firewalld/zones/public.xml/zone/#text[2] = " " 
/files/etc/firewalld/zones/public.xml/zone/description 
/files/etc/firewalld/zones/public.xml/zone/description/#text = "For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted." 
/files/etc/firewalld/zones/public.xml/zone/#text[3] = " " 
/files/etc/firewalld/zones/public.xml/zone/service[1] = "#empty" 
/files/etc/firewalld/zones/public.xml/zone/service[1]/#attribute 
/files/etc/firewalld/zones/public.xml/zone/service[1]/#attribute/name = "dhcpv6-client" 
/files/etc/firewalld/zones/public.xml/zone/#text[4] = " " 
/files/etc/firewalld/zones/public.xml/zone/service[2] = "#empty" 
/files/etc/firewalld/zones/public.xml/zone/service[2]/#attribute 

我再試試

augtool> defnode service /files/etc/firewalld/zones/public.xml/zone/service[attribute/#name="http"] 
augtool> set $service "#empty" 
augtool> set $service/#attribute/name "http" 
augtool> save 

,如果我現在看一下public.xml文件,它看起來像:

<?xml version="1.0" encoding="utf-8"?> 
<zone> 
    <short>Public</short> 
    <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> 
    <service name="dhcpv6-client"/> 
    <service name="ssh"/> 
<service name="http"/> 
</zone> 

任何人都可以建議我如何保存在我添加的<service name="http">條目之前的縮進嗎?

回答

1

使用Augeas添加新節點時,不可能保留縮進。