I would like to append the new group to the existing AllowGroups in /etc/ssh/sshd_config file without disturbing the existing group. I tried with lineinfile module but unfortunately its failing or overwriting existing groups. Can anyone please provide the clue on logic?
existing setup:
grep AllowGroups /etc/ssh/sshd_config
AllowGroups x y z
required setup: let’s assume “a” is new group, then i am looking as below
grep AllowGroups /etc/ssh/sshd_config
AllowGroups x y z a <-----group “a” needs to be added at the end of the line
"When modifying a line the regexp should typically match both the
initial state of the line as well as its state after replacement by
line to ensure idempotence."
Remember to update the sshd_config to the proper path ie. /etc/ssh/sshd_config
➜ ~ grep ‘^AllowGroups’ sshd_config
AllowGroups a b c
➜ ~ ansible-playbook -i localhost, allow.yml
PLAY [Configure sshd groups] ******************************************************************************************************************************************************************
Playbook run took 0 days, 0 hours, 0 minutes, 1 seconds
➜ ~ grep ‘^AllowGroups’ sshd_config
AllowGroups a b c x y z