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

后端 未结 5 1723
天命终不由人
天命终不由人 2021-01-11 15:34

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:

AllowUs         


        
5条回答
  •  醉梦人生
    2021-01-11 16:26

    This worked for me

     - name: Add Group to AllowGroups
       lineinfile: 
         dest=/etc/ssh/sshd_config
         backup=True
         backrefs=True
         state=present
         regexp='^(AllowGroups(?!.*\b{{ groupname }}\b).*)$'
         line='\1 {{ groupname }}'
    

提交回复
热议问题