thank you so much Vladimir and Jorge Regards, Suresh
On Fri, Oct 29, 2021 at 3:11 AM Vladimir Botka <[email protected]> wrote: > On Fri, 29 Oct 2021 01:57:17 +0530 > Suresh Karpurapu <[email protected]> wrote: > > > > > # grep AllowGroups /etc/ssh/sshd_config > > > > AllowGroups x y z > > > > > > > > # grep AllowGroups /etc/ssh/sshd_config > > > > AllowGroups x y z a <-----group "a" needs to be > added at > > > > the end of the line > > > > Enable *backrefs* and create non-greedy capture group in front of the > > > potentially existent "a" group > > > > > > - lineinfile: > > > path: /etc/ssh/sshd_config > > > backrefs: true > > > regexp: '^\s*AllowGroups\s+(.*?)(\s+a)*$' > > > line: 'AllowGroups \1 a' > > > > > > The task is idempotent. Quoting from *regexp* > > > > > > > https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html#parameter-regexp > > > > > > "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." > > > How can we loop if we need to append multiple groups. > > Put them into a variable, e.g. > > - lineinfile: > path: /etc/ssh/sshd_config > backrefs: true > regexp: '^\s*AllowGroups\s+(.*?)(\s+{{ add_groups }})*$' > line: 'AllowGroups \1 {{ add_groups }}' > > -- > Vladimir Botka > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAHedzhLP%3DKRUe26pTFNFgNJmQcvYk%3DfM_6TxJdjtMcXRioN4WQ%40mail.gmail.com.
