Brilliant - thank you
On Sunday, January 26, 2020 at 1:15:40 PM UTC, Kai Stian Olstad wrote:
>
> On 26.01.2020 13:50, Waqar Khan wrote:
> > 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 can create a variable that contains the information
>
> allowusers:
> Amazon: ec2-user
> Centos: centos
>
> And then you only need one task
> - name: sshd_config
> lineinfile:
> path: /etc/ssh/sshd_config
> regexp: "^AllowUsers"
> line: AllowUsers {{ allowusers[ansible_distribution] }}
> notify: restart sshd
>
>
> --
> Kai Stian Olstad
>
--
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/d24260e5-4ad0-413e-862a-abbb1180d3d8%40googlegroups.com.