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,

Le 26/01/2020 à 13:50, Waqar Khan a écrit :
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fc08397d-3bb8-4087-93f2-9a4d85378906%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/fc08397d-3bb8-4087-93f2-9a4d85378906%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7318ce4d-08ad-00da-fc54-3fd495944775%40lenhof.eu.org.

Reply via email to