# Basic beginner question

**URL:** <https://forum.ansible.com/t/basic-beginner-question/32061>\
**Category:** Ansible Project\
**Created:** [January 26, 2020, 12:50pm UTC](https://forum.ansible.com/t/basic-beginner-question/32061 "2020-01-26T12:50:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Waqar\_Khan](https://avatars.discourse-cdn.com/v4/letter/w/e47774/32.png) [@Waqar\_Khan](https://forum.ansible.com/u/Waqar_Khan)\
**Post date:** [January 26, 2020, 12:50pm UTC](https://forum.ansible.com/t/basic-beginner-question/32061/1 "2020-01-26T12:50:06Z")

</div>

Starting out with ansible and trying to configure sshd config. Here is what I have, it works but is there a better way to do with for future reference. e.g. if I have many different distributions it looks like a lot of copying. Can I combine the 2 tasks?

- name: sshd Amazon  
lineinfile:  
state: present  
path: /etc/ssh/sshd\_config  
regexp: “^AllowUsers”  
line: AllowUsers ec2-user  
when: ansible\_distribution == ‘Amazon’  
notify:

- restart sshd

- name: sshd Centos  
lineinfile:  
state: present  
path: /etc/ssh/sshd\_config  
regexp: “^AllowUsers”  
line: AllowUsers centos  
when: ansible\_distribution == ‘Centos’  
notify:

- restart sshd

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 26, 2020, 1:15pm UTC](https://forum.ansible.com/t/basic-beginner-question/32061/2 "2020-01-26T13:15:18Z")

</div>

You can create a variable that contains the information

allowusers:  
&nbsp;&nbsp;&nbsp;Amazon: ec2-user  
&nbsp;&nbsp;&nbsp;Centos: centos

And then you only need one task  
- name: sshd\_config  
&nbsp;&nbsp;&nbsp;lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /etc/ssh/sshd\_config  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: "^AllowUsers"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line: AllowUsers {{ allowusers[ansible\_distribution] }}  
&nbsp;&nbsp;&nbsp;notify: restart sshd

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [January 26, 2020, 1:32pm UTC](https://forum.ansible.com/t/basic-beginner-question/32061/3 "2020-01-26T13:32:03Z")

</div>

Hi,

You probably looking for ansible\_os\_family which is RedHat for these distributions : RedHat EL, CentOS, Amazon, etc…

You should probably test the major version (between 6 and 7, there’s service and systemctl which are kind different for example, I suppose you’re not modifying only ssh config)

So you’re when directive should be something like this :

when: ansible\_os\_family == ‘RedHat’ and ansible\_distribution\_major\_version in [‘6’,‘7’]

Regards,

---

<div class="post-metadata">

**Author:** ![Waqar\_Khan](https://avatars.discourse-cdn.com/v4/letter/w/e47774/32.png) [@Waqar\_Khan](https://forum.ansible.com/u/Waqar_Khan)\
**Post date:** [January 26, 2020, 1:54pm UTC](https://forum.ansible.com/t/basic-beginner-question/32061/4 "2020-01-26T13:54:46Z")

</div>

Brilliant - thank you
