francsw / EX407-Ansible-Automation

Red Hat Certified Specialist in Ansible Automation (EX407) Preparation Course
0 stars 0 forks source link

LAB: Working with Ansible Templates, Variables, and Facts #7

Open francsw opened 3 years ago

francsw commented 3 years ago
  %sysops 34.124.22.55 = (ALL) ALL
  Host_Alias WEBSERVERS = server1, server2
  Host_Alias DBSERVERS = serverA, serverB
  %httpd WEBSERVERS = /bin/su - webuser
  %dba DBSERVERS = /bin/su - dbuser
francsw commented 3 years ago
---
- hosts: test
  gather_facts: yes
  become: yes

  tasks:
  - name: Create sudoers template
    template:
      src: hardened.j2
      dest: /etc/sudoers.d/hardened.out
      validate: /usr/sbin/visudo -cf %s
%sysops {{ ansible_default_ipv4.address }} = (ALL) ALL
Host_Alias WEBSERVERS = {{ groups['WEBSERVERS'] | join(" ,") }}
Host_Alias DBSERVERS = {{ groups['DBSERVERS'] | join(" ,") }}
%httpd WEBSERVERS = /bin/su - webuser
%dba DBSERVERS = /bin/su - dbuser
francsw commented 3 years ago
{% ... %} for Statements
{{ ... }} for Expressions to print to the template output
{# ... #} for Comments not included in the template output
#  ... ## for Line Statements