Ansible: insert a single word on an existing line in a file


I have to use Ansible modules in order to edit the /etc/ssh/sshd_config file – every time I create a new user I want to append it at these two lines:

At this moment I’m using the shell module to execute a sed command but would like to use lineinfile, if possible

Any suggestions would be sincerely appreciated.


You could do it in a single play with a newline, but I think it’s cleaner to use two lineinfile plays for this.

Note that groups is a reserved word so don’t use that as a variable name.

Leave a Reply