adding user@hostname in sshd config

34 views
Skip to first unread message

Amit Sharma

unread,
Jun 14, 2022, 9:52:37 AM6/14/22
to Ansible Project
Hi Team,

I am trying to create a playbook to add the allow users and hostname dynamically in SSHD config. Ansible playbook should check the entry and add it if its not exist. 

I have written the below code and it is duplicating the same content and its not checking idempotent. The  below code is not adding *@* *@dcecpn0.spt.com. Can you please check and provide your suggestions.

  lineinfile:
    path: "{{ security_ssh_config_path }}"
    backrefs: yes  
    regexp: '(^AllowUsers(?!.*b{{ security_ssh_allowed_users }}@{{ security_ssh_allowed_hosts }}\b).*)$'
    line: '\1 {{ security_ssh_allowed_users }}@{{ security_ssh_allowed_hosts }}'
    state: present

Thanks 
Amit.
Reply all
Reply to author
Forward
0 new messages