如何使用 Augeas 设置 sssd.conf 中的 ipa_hostname 指令的值

如何使用 Augeas 设置 sssd.conf 中的 ipa_hostname 指令的值

使用 Puppet 版本

掌握:puppetserver 6.7

客户:puppet-agent 6.10

我在其他模块中还有其他 Augeas 代码,它们运行良好。

示例 sssd.conf

[sssd]
services = nss, sudo, pam, ssh
config_file_version = 2
domains = abc.def.net

[domain/abc.def.net]
cache_credentials = True
id_provider = ipa
auth_provider = ipa
access_provider = ipa
ipa_hostname = xxx.abc.def.net

...

我需要更新/验证 [domain/abc.def.net] 部分中的 ipa_hostname 值。我搞不清楚这个 augeas 代码哪里出错了

    augeas { "sssd.conf":
      context => "/files/etc/sssd/sssd.conf",
      changes => [
                "set ipa_hostname xxx",
                ],
      notify    => Service["sssd"]
    }

以下是调试输出:

Debug: Augeas[sssd.conf](provider=augeas): Opening augeas with root /, lens path , flags 64
Debug: Augeas[sssd.conf](provider=augeas): Augeas version 1.12.0 is installed
Debug: Augeas[sssd.conf](provider=augeas): Will attempt to save and only run if files changed
Debug: Augeas[sssd.conf](provider=augeas): sending command 'set' with params ["/files/etc/sssd/sssd.conf/ipa_hostname", "no"]
Debug: Augeas[sssd.conf](provider=augeas): Put failed on one or more files, output from /augeas//error:
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error = put_failed
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/path = /files/etc/sssd/sssd.conf/
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/lens = /opt/puppetlabs/puppet/share/augeas/lenses/dist/sssd.aug:33.13-.53:
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/message = Failed to match tree under /

     { "target" = "sssd" }
     { "target" = "domain/test.hfgs.net" }
     { "target" = "nss" }
     { "target" = "pam" }
     { "target" = "sudo" }
     { "target" = "autofs" }
     { "target" = "ssh" }
     { "target" = "pac" }
     { "ipa_hostname" = "xxx" }

  with pattern
   (    { /#comment/ = /[^\t\n\r ].*[^\t\n\r ]|[^\t\n\r ]/ }
      | { })*
    { /target/ = /[^]\n\r]+/ }*

Debug: Augeas[sssd.conf](provider=augeas): Closed the augeas connection
Error: /Stage[main]/Testaugeas/Augeas[sssd.conf]: Could not evaluate: Save failed, see debug output for details

答案1

花了几天时间,我终于搞明白了。我添加了一些额外的代码来展示如何解决同一文件中的另一个部分。希望这对你有所帮助。

  $domain = abc.net
  augeas { "sssd.conf ipa_hostname":
    lens    => 'sssd.lns',
    incl    => '/etc/sssd/sssd.conf',
    changes => [
      "set target[ . = 'sssd']/services 'nss, sudo, pam, ssh'",
      "set target[ . = 'sssd']/config_file_version 2",
      "set target[ . = 'sssd']/domains ${domain}",
      "set target[ . = 'domain/${domain}']/ipa_hostname ${hostname}.${domain}",
    ],
    notify  => Service["sssd"]
  }

相关内容