Browse Source

Lots of little fixes and cleanup

master
lavenderguiar 3 years ago
parent
commit
71e698e9ef
  1. 6
      defaults/main.yml
  2. 27
      tasks/add_user.yml
  3. 2
      tasks/ansible_dependencies.yml
  4. 13
      tasks/firewall.yml
  5. 2
      tasks/main.yml
  6. 8
      tasks/preflight.yml
  7. 2
      templates/etc/ssh/sshd_config.j2

6
defaults/main.yml

@ -6,10 +6,12 @@ preflight__timezone: UTC
firewall__ssh_rule: limit firewall__ssh_rule: limit
# User # User
admin_user: "admin" user: "admin"
admin_group: "admin" group: "admin"
# SSH Config # SSH Config
ssh__port: 8822 ssh__port: 8822
ssh__password_authentication: "no" ssh__password_authentication: "no"
ssh__address_family: "inet" ssh__address_family: "inet"
ssh__keys: []

27
tasks/add_user.yml

@ -1,10 +1,10 @@
--- ---
- name: add_user | Add admin group - name: linode_preflight | add_user | Add admin group
group: group:
name: "{{ admin_group }}" name: "{{ group }}"
state: present state: present
- name: add_user | Allow 'admin' group to have passwordless sudo - name: linode_preflight | add_user | Allow 'admin' group to have passwordless sudo
lineinfile: lineinfile:
dest: /etc/sudoers dest: /etc/sudoers
state: present state: present
@ -13,27 +13,28 @@
validate: 'visudo -cf %s' validate: 'visudo -cf %s'
become: yes become: yes
- name: add_user | Add admin user - name: linode_preflight | add_user | Add admin user
user: user:
name: "{{ admin_user }}" name: "{{ user }}"
group: "{{ admin_group }}" group: "{{ group }}"
state: present state: present
create_home: yes create_home: yes
shell: /bin/bash
become: yes become: yes
- name: add_user | Ensure admin user ssh directory exists - name: linode_preflight | add_user | Ensure admin user ssh directory exists
file: file:
path: "/home/{{ admin_user }}/.ssh/" path: "/home/{{ user }}/.ssh/"
state: directory state: directory
owner: "{{ admin_user }}" owner: "{{ user }}"
group: "{{ admin_group }}" group: "{{ group }}"
mode: 0700 mode: 0700
become: yes become: yes
- name: add_user | Add SSH keys to admin user - name: linode_preflight | add_user | Add SSH keys to admin user
authorized_key: authorized_key:
user: "{{ admin_user }}" user: "{{ user }}"
state: present state: present
key: "{{ item.key }}" key: "{{ item.key }}"
with_items: "{{ ssh_keys }}" with_items: "{{ ssh__keys }}"
become: yes become: yes

2
tasks/ansible_dependencies.yml

@ -1,5 +1,5 @@
--- ---
- name: linode-preflight | Install Python - name: linode-preflight | ansible dependencies | Install Python
raw: test -e /usr/bin/python || (sudo apt-get -y update && sudo apt-get install -y python2-minimal) raw: test -e /usr/bin/python || (sudo apt-get -y update && sudo apt-get install -y python2-minimal)
register: common__pyout register: common__pyout
become: yes become: yes

13
tasks/firewall.yml

@ -1,11 +1,11 @@
--- ---
- name: firewall | install ufw - name: linode_preflight | firewall | install ufw
apt: apt:
pkg: ufw pkg: ufw
state: present state: present
become: yes become: yes
- name: firewall | Open ssh port - name: linode_preflight | firewall | Open ssh port
ufw: ufw:
state: enabled state: enabled
rule: "{{ firewall__ssh_rule }}" rule: "{{ firewall__ssh_rule }}"
@ -16,21 +16,21 @@
- 8822 - 8822
become: yes become: yes
- name: firewall | deny all incoming connections - name: linode_preflight | firewall | deny all incoming connections
ufw: ufw:
state: enabled state: enabled
policy: deny policy: deny
direction: incoming direction: incoming
become: yes become: yes
- name: firewall | allow all outgoing connections - name: linode_preflight | firewall | allow all outgoing connections
ufw: ufw:
state: enabled state: enabled
policy: allow policy: allow
direction: outgoing direction: outgoing
become: yes become: yes
- name: firewall | allow all connections from localhost - name: linode_preflight | firewall | allow all connections from localhost
ufw: ufw:
state: enabled state: enabled
from: "127.0.0.1" from: "127.0.0.1"
@ -38,7 +38,7 @@
proto: any proto: any
become: yes become: yes
- name: firewall | Copy SSH config - name: linode_preflight | firewall | Copy SSH config
template: template:
src: "etc/ssh/sshd_config.j2" src: "etc/ssh/sshd_config.j2"
dest: "/etc/ssh/sshd_config" dest: "/etc/ssh/sshd_config"
@ -46,4 +46,3 @@
validate: '/usr/sbin/sshd -t -f %s' validate: '/usr/sbin/sshd -t -f %s'
become: yes become: yes
notify: restart sshd notify: restart sshd

2
tasks/main.yml

@ -2,4 +2,4 @@
- include_tasks: ansible_dependencies.yml - include_tasks: ansible_dependencies.yml
- include_tasks: preflight.yml - include_tasks: preflight.yml
- include_tasks: add_user.yml - include_tasks: add_user.yml
- include_tasks: firewall.yml - include_tasks: firewall.yml # Always run last. Then swap Ansible user.

8
tasks/preflight.yml

@ -1,23 +1,23 @@
--- ---
- name: preflight | install ntp - name: linode_preflight | preflight | install ntp
apt: apt:
name: ntp name: ntp
state: present state: present
become: yes become: yes
- name: preflight | ensure ntp is running on boot - name: linode_preflight | preflight | ensure ntp is running on boot
service: service:
name: ntp name: ntp
state: started state: started
enabled: yes enabled: yes
become: yes become: yes
- name: preflight | Set Timezone - name: linode_preflight | preflight | Set Timezone
timezone: timezone:
name: "{{ preflight__timezone }}" name: "{{ preflight__timezone }}"
become: yes become: yes
- name: preflight | copy 10periodic unattended upgrades - name: linode_preflight | preflight | copy 10periodic unattended upgrades
template: template:
src: "etc/apt/apt.conf.d/10periodic.j2" src: "etc/apt/apt.conf.d/10periodic.j2"
dest: "/etc/apt/apt.conf.d/10periodic" dest: "/etc/apt/apt.conf.d/10periodic"

2
templates/etc/ssh/sshd_config.j2

@ -31,7 +31,7 @@ AddressFamily {{ ssh__address_family }}
# Authentication: # Authentication:
#LoginGraceTime 2m #LoginGraceTime 2m
PermitRootLogin yes PermitRootLogin no
#StrictModes yes #StrictModes yes
#MaxAuthTries 6 #MaxAuthTries 6
#MaxSessions 10 #MaxSessions 10

Loading…
Cancel
Save