# adding user@hostname in sshd config

**URL:** <https://forum.ansible.com/t/adding-user-hostname-in-sshd-config/36736>\
**Category:** Ansible Project\
**Created:** [June 14, 2022, 1:52pm UTC](https://forum.ansible.com/t/adding-user-hostname-in-sshd-config/36736 "2022-06-14T13:52:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Sharma1](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Amit\_Sharma1](https://forum.ansible.com/u/Amit_Sharma1)\
**Post date:** [June 14, 2022, 1:52pm UTC](https://forum.ansible.com/t/adding-user-hostname-in-sshd-config/36736/1 "2022-06-14T13:52:36Z")

</div>

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.
