You are not logged in.
I have a use case where I need to edit a systemd unit on ~1700 Arch Linux systems.
Namely this one:
$ cat /etc/systemd/network/terminals.netdev
[NetDev]
Name = terminals
Kind = wireguard
Description = Terminal maintenance VPN.
[WireGuard]
...
I want to add MTUBytes = 1280 to the [NetDev] section, if the key MTUBytes does not yet exist in that section, so that it looks like:
[NetDev]
Name = terminals
Kind = wireguard
Description = Terminal maintenance VPN.
MTUBytes = 1280
[WireGuard]
...
afterwards.
Is there a command line tool that can manipulate that kind of INI-style systemd units or do I need to write one on my own?
Edit:
In case that was not clear: I cannot just sync the same file to all systems, since they differ in the [WireGuard] and [WireGuardPeer] sections, since all systems of course have different keys.
Last edited by schard (2022-12-02 14:43:33)
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
If you can SSH to all these hosts you can use ansible. I would say it's the most fitting as you can then use it to further maintain these systems. Ansible offers some modules to do the kind of replacement you want, like https://docs.ansible.com/ansible/latest … odule.html.
Offline
The only thing that comes to mind is a more general tool: Augeas. Checking it out further is on my TODO list, but it does seem to support INI files with a sparsely documented systemd lens on top of that.
Since Ansible was mentioned (although not by OP), there's https://github.com/paluh/ansible-augeas; SaltStack and Puppet support it without needing third-party modules. Salt also has a simple/limited INI module to avoid the regex hell of lineinfile.
Offline
I'd just use sed. Run the following on each system:
#!/bin/sh
sed -i '
/^\[NetDev\]$/ {
:loop
n
/^MTUBytes/bend
/^$/ {
iMTUBytes = 1280
bend
}
bloop
:end
}' /etc/systemd/network/terminals.netdev
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for all your suggestions
@pitastrudl Yes, the systems are maintained via SSH. Ansible is not suitable for our changing systems setup. The deployment itself is not the issue.
@Trilby Thank you. I thought about using sed, but my sed-foo is not strong enough. I'll go with your solution.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline