Puppet - Augeas Lens for systemd

When applying changes to /etc/systemd/system.conf, using the systemd.lns augeas lens, I needed to change the CPU Affinity parameter.

using the puppetforge systemd module, I wanted to set YAML to set the line
CPUAffinity=0 1 2 3
in /etc/systemd/system.conf

I already discovered through the systemd-system.conf man page that CentOS 7 doesn’t accept ranges (even though the freedesktop.org doco https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html suggested otherwise)
so I need a list.

When using

systemd::changes:
  - "set Manager/CPUAffinity/value 0 1 2 3"

It failed to parse properly and the following error occurred.

Debug: Augeas[/etc/systemd/system.conf](provider=augeas): Opening augeas with root /, lens path /opt/puppetlabs/puppet/cache/lib/augeas/lenses, flags 64
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): Augeas version 1.4.0 is installed
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): Will attempt to save and only run if files changed
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): sending command 'set' with params ["/files/etc/systemd/system.conf/Manager/CPUAffinity/value", "0 1 2 3 4"]
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): Put failed on one or more files, output from /augeas//error:
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): /augeas/files/etc/systemd/system.conf/error = put_failed
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): /augeas/files/etc/systemd/system.conf/error/path = /files/etc/systemd/system.conf/Manager/CPUAffinity
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): /augeas/files/etc/systemd/system.conf/error/lens = /opt/puppetlabs/puppet/share/augeas/lenses/dist/systemd.aug:96.6-.44:
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): /augeas/files/etc/systemd/system.conf/error/message = Failed to match

This shows that the systemd augeas lens is not expecting any spaces in the values argument.

I found a post from Dominic Cleal (the author of the systemd augeas lens), discussing another lens,
https://www.redhat.com/archives/augeas-devel/2013-March/msg00032.html
This indicated may need to build array elements through individual line items.

Whilst his suggestion of setting /files/etc/ssh/sshd_config/AllowUsers/1 user didn’t directly work here (e.g. - set Manager/CPUAffinity/value/1 0" ; - "set Manager/CPUAffinity/value/2 1, etc), it got me thinking that it probably still wants to build up array elements.

I found
https://docs.puppet.com/guides/augeas.html

referenced array elements in the form of
/files/etc/exports/dir[1]

Solution

It turns out, if you want space separated values in system.conf using augeas, you can use the following

systemd::changes:
  - "set Manager/CPUAffinity/value[1] 0"
  - "set Manager/CPUAffinity/value[2] 1"
  - "set Manager/CPUAffinity/value[3] 2"
  - "set Manager/CPUAffinity/value[4] 3"

Which then results in the following when running puppet

Debug: Augeas[/etc/systemd/system.conf](provider=augeas): sending command 'set' with params ["/files/etc/systemd/system.conf/Manager/CPUAffinity/value[1]", "0"]
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): sending command 'set' with params ["/files/etc/systemd/system.conf/Manager/CPUAffinity/value[2]", "1"]
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): sending command 'set' with params ["/files/etc/systemd/system.conf/Manager/CPUAffinity/value[3]", "2"]
Debug: Augeas[/etc/systemd/system.conf](provider=augeas): sending command 'set' with params ["/files/etc/systemd/system.conf/Manager/CPUAffinity/value[4]", "3"]
Debug: Executing: 'diff -u /etc/systemd/system.conf /etc/systemd/system.conf.augnew'
Notice: Augeas[/etc/systemd/system.conf](provider=augeas):
--- /etc/systemd/system.conf    2016-08-23 08:09:29.072874233 +1000
+++ /etc/systemd/system.conf.augnew     2016-08-23 08:17:22.205565976 +1000
@@ -55,4 +55,4 @@
#DefaultLimitNICE=
#DefaultLimitRTPRIO=
#DefaultLimitRTTIME=
-CPUAffinity=2
+CPUAffinity=0 1 2 3

I've since determined that a sed style search and replace works more effectively, but this was still a good learning exercse.