diff --git a/hosts-caleb b/hosts-caleb new file mode 100644 index 0000000..1d0e0b5 --- /dev/null +++ b/hosts-caleb @@ -0,0 +1,8 @@ +[allservers] +cfultz.com +virginialinux.org +23.94.94.221 +107.172.167.134 +198.46.217.112 +69.10.44.219 +67.217.51.59 diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml new file mode 100644 index 0000000..64c6d4c --- /dev/null +++ b/roles/common/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- name: Update and upgrade apt packages + become: true + apt: + upgrade: yes + update_cache: yes + cache_valid_time: 86400 + +- name: Check to see if reboot is needed + register: reboot_required_file + stat: path=/var/run/reboot-required get_checksum=false + +- name: Reboot the server + become: true + reboot: + msg: "Reboot initiated by Ansible due to kernel updates" + connect_timeout: 5 + reboot_timeout: 300 + pre_reboot_delay: 0 + post_reboot_delay: 30 + test_command: uptime + when: reboot_required_file.stat.exists diff --git a/roles/security/handlers/main.yml b/roles/security/handlers/main.yml new file mode 100644 index 0000000..3fda082 --- /dev/null +++ b/roles/security/handlers/main.yml @@ -0,0 +1,8 @@ +- name: Restart service ssh + become: true + ansible.builtin.service: + name: sshd + state: restarted + ansible.builtin.service: + name: ssh + state: restarted \ No newline at end of file diff --git a/roles/security/tasks/main.yml b/roles/security/tasks/main.yml new file mode 100644 index 0000000..91b6092 --- /dev/null +++ b/roles/security/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- name: Set LoginGraceTime to 0 on SSH + become: true + ansible.builtin.lineinfile: + path: /etc/ssh/sshd_config + regexp: '^#LoginGraceTime' + line: LoginGraceTime + ansible.builtin.lineinfile: + path: /etc/ssh/sshd_config + regexp: '^LoginGraceTime' + line: LoginGraceTime 0 + notify: Restart service ssh \ No newline at end of file diff --git a/run.sh b/run.sh index 4054c32..c722409 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -/usr/bin/ansible-playbook -i hosts update.yml --ask-become-pass +/usr/bin/ansible-playbook -i hosts-caleb site.yml --ask-become-pass diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..07183ad --- /dev/null +++ b/site.yml @@ -0,0 +1,6 @@ +- name: Run updates on servers + hosts: all + gather_facts: no + roles: + - common + # - security