francsw / EX407-Ansible-Automation

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

LAB: Working with Ansible Roles #8

Open francsw opened 3 years ago

francsw commented 3 years ago
francsw commented 3 years ago

ansible-galaxy init ./roles/baseline

---
# tasks file for ./roles/baseline

- name: MOTD template
  copy:
    src: motd
    dest: /etc/motd
    owner: root
    group: root
    mode: 0644

- name: Add and enable EPEL repo
  package:
    name: epel-release.noarch
    state: latest

- name: Install the nagios plugin
  package:
    name: nagios-common
    state: latest

- name: Add Nagios server to hosts file
  lineinfile:
    path: /etc/hosts
    line: "192.168.60.123 nagios.lab.local"
    state: present

- name: Create users
  user:
    name: noc
    create_home: yes
    generate_ssh_key: yes

- name: Copy auth keys
  copy:
    src: authorized_keys_noc
    dest: /home/noc/.ssh/authorized_keys
    owner: noc
    group: noc
    mode: 0600

Create files in ./roles/baseline/files/motd and authorized_keys