2020-10-28 22:15:23 +01:00
|
|
|
- hosts: all
|
2022-04-15 15:51:58 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- always
|
2022-04-15 15:51:58 +02:00
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
tasks:
|
|
|
|
- name: Get dpkg arch
|
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
|
|
|
ansible.builtin.shell: dpkg --print-architecture
|
|
|
|
register: _apt_arch
|
2022-10-18 22:20:04 +02:00
|
|
|
changed_when: false
|
2022-04-15 15:51:58 +02:00
|
|
|
|
|
|
|
- hosts: all:!unifi
|
|
|
|
become: "{{ do_become }}"
|
2020-10-28 22:15:23 +01:00
|
|
|
tags: [never, init]
|
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
|
|
|
|
pre_tasks:
|
2021-08-16 23:50:14 +02:00
|
|
|
- include_tasks: tasks/users.yml
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
loop_control:
|
|
|
|
loop_var: user
|
2020-10-28 22:15:23 +01:00
|
|
|
|
|
|
|
- name: Change hostname
|
|
|
|
when: "set_hostname is defined"
|
|
|
|
register: new_hostname
|
|
|
|
ansible.builtin.hostname:
|
|
|
|
name: "{{ set_hostname }}"
|
|
|
|
|
|
|
|
- name: Change hostname in hosts
|
|
|
|
when: new_hostname.changed
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /etc/hosts
|
|
|
|
regexp: '^127\.0\.0\.1 localhost'
|
|
|
|
line: "127.0.0.1 localhost {{ set_hostname }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0644"
|
|
|
|
|
|
|
|
- name: Reboot the server
|
|
|
|
ansible.builtin.reboot:
|
|
|
|
msg: "Reboot initiated by Ansible due to hostname change"
|
|
|
|
connect_timeout: 5
|
|
|
|
reboot_timeout: 300
|
|
|
|
pre_reboot_delay: 2
|
|
|
|
post_reboot_delay: 30
|
|
|
|
test_command: uptime
|
|
|
|
when: new_hostname.changed
|
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
- include_tasks: tasks/remove_prox_ee_apt.yml
|
|
|
|
when: inventory_hostname in groups['prox']
|
|
|
|
|
2021-08-17 00:13:23 +02:00
|
|
|
- name: Update apt cache
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
2021-08-17 00:13:23 +02:00
|
|
|
ansible.builtin.apt:
|
|
|
|
update_cache: true
|
|
|
|
cache_valid_time: 1
|
|
|
|
|
2020-10-28 22:15:23 +01:00
|
|
|
roles:
|
|
|
|
- role: geerlingguy.ntp
|
|
|
|
- role: geerlingguy.security
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
2020-10-28 22:15:23 +01:00
|
|
|
tasks:
|
|
|
|
- name: Install packages
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
2020-10-28 22:15:23 +01:00
|
|
|
ansible.builtin.apt:
|
2022-11-08 21:41:19 +01:00
|
|
|
name: "{{package_list}}"
|
2020-10-28 22:15:23 +01:00
|
|
|
state: latest
|
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
- name: Install pip packages
|
|
|
|
ansible.builtin.pip:
|
|
|
|
name:
|
|
|
|
- github3.py
|
|
|
|
|
2021-02-13 15:39:14 +01:00
|
|
|
- hosts: docker
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- docker
|
2021-02-13 15:39:14 +01:00
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
post_tasks:
|
|
|
|
- name: Install pip packages
|
|
|
|
ansible.builtin.pip:
|
|
|
|
name:
|
|
|
|
- docker
|
2021-08-16 23:52:40 +02:00
|
|
|
|
|
|
|
- name: Create plugin directory if not present
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/home/{{ item.username }}/.docker/cli-plugins/"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ item.username }}"
|
|
|
|
group: "{{ item.groupname }}"
|
|
|
|
mode: "0775"
|
|
|
|
loop: "{{ docker_users_obj }}"
|
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
- name: Get latest release of a public repository
|
|
|
|
community.general.github_release:
|
|
|
|
user: docker
|
|
|
|
repo: compose
|
|
|
|
action: latest_release
|
|
|
|
register: comp_cli
|
|
|
|
|
2021-08-16 23:52:40 +02:00
|
|
|
- name: Install compose plugin
|
|
|
|
ansible.builtin.get_url:
|
2022-04-15 15:51:58 +02:00
|
|
|
url: "https://github.com/docker/compose/releases/download/{{comp_cli.tag}}/docker-compose-linux-{{ ansible_architecture }}"
|
|
|
|
dest: "/home/{{ users.0.username }}/.docker/cli-plugins/docker-compose"
|
2021-08-16 23:52:40 +02:00
|
|
|
mode: "0755"
|
2022-04-15 15:51:58 +02:00
|
|
|
owner: "{{ users.0.username }}"
|
|
|
|
group: "{{ users.0.groupname }}"
|
2021-08-16 23:52:40 +02:00
|
|
|
|
2021-02-13 15:39:14 +01:00
|
|
|
roles:
|
|
|
|
- role: geerlingguy.docker
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu'
|
2021-02-13 15:39:14 +01:00
|
|
|
|
|
|
|
- hosts: kube
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- init
|
|
|
|
- kube
|
|
|
|
- never
|
2021-02-13 15:39:14 +01:00
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
tasks:
|
2022-10-18 22:18:54 +02:00
|
|
|
- name: Install runtime dependencies
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:18:54 +02:00
|
|
|
ansible.builtin.apt:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- fuse-overlayfs
|
|
|
|
- nfs-common
|
|
|
|
- open-iscsi
|
|
|
|
- name: Include Containerd role
|
2022-04-15 15:51:58 +02:00
|
|
|
include_role:
|
2022-10-18 22:18:54 +02:00
|
|
|
name: geerlingguy.containerd
|
2022-04-15 15:51:58 +02:00
|
|
|
apply:
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:18:54 +02:00
|
|
|
- name: Include Docker role
|
2022-04-15 15:51:58 +02:00
|
|
|
include_role:
|
2022-10-18 22:18:54 +02:00
|
|
|
name: geerlingguy.docker
|
2022-04-15 15:51:58 +02:00
|
|
|
apply:
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-04-15 15:51:58 +02:00
|
|
|
- name: Include Kubernetes role
|
|
|
|
include_role:
|
|
|
|
name: kubernetes
|
|
|
|
- name: Include ZFS role
|
|
|
|
when: inventory_hostname in groups['zfs']
|
|
|
|
include_role:
|
|
|
|
name: zfs
|
|
|
|
- name: Include NFS role
|
|
|
|
when: inventory_hostname in groups['nfs']
|
|
|
|
include_role:
|
|
|
|
name: geerlingguy.nfs
|
|
|
|
apply:
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2021-02-13 15:39:14 +01:00
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
- hosts: prox
|
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- prox
|
|
|
|
- update
|
2022-04-15 15:51:58 +02:00
|
|
|
roles:
|
|
|
|
- role: ironicbadger_ansible-role-proxmox-nag-removal
|
|
|
|
- role: proxmox
|
2021-02-13 15:39:14 +01:00
|
|
|
|
2022-10-18 22:20:04 +02:00
|
|
|
- hosts: raspberries
|
2020-10-28 22:15:23 +01:00
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- init
|
|
|
|
- raspberries
|
|
|
|
- update
|
2022-04-15 15:51:58 +02:00
|
|
|
tasks:
|
|
|
|
- name: Install packages
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-04-15 15:51:58 +02:00
|
|
|
ansible.builtin.apt:
|
2022-11-08 21:41:19 +01:00
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- libraspberrypi-bin
|
|
|
|
- linux-modules-extra-raspi
|
|
|
|
- vlan
|
|
|
|
|
|
|
|
- name: Add the 802.1q module
|
|
|
|
community.general.modprobe:
|
|
|
|
name: 8021q
|
|
|
|
state: present
|
2020-10-28 22:15:23 +01:00
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
- name: Place PoE fan file
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-04-15 15:51:58 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
content: |
|
|
|
|
# Ansible managed
|
|
|
|
|
|
|
|
dtoverlay=rpi-poe
|
|
|
|
dtparam=poe_fan_temp0=57000
|
|
|
|
dtparam=poe_fan_temp1=60000
|
|
|
|
dtparam=poe_fan_temp2=63000
|
|
|
|
dtparam=poe_fan_temp3=66000
|
2022-10-18 22:13:55 +02:00
|
|
|
|
|
|
|
dtoverlay=vc4-fkms-v3d
|
2022-04-15 15:51:58 +02:00
|
|
|
dest: /boot/firmware/usercfg.txt
|
|
|
|
|
2022-10-18 22:13:55 +02:00
|
|
|
- hosts: piholes
|
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
tags:
|
|
|
|
- pihole
|
|
|
|
- update
|
|
|
|
roles:
|
|
|
|
- role: pihole_updatelist
|
|
|
|
- role: pi_dnsmasq
|
|
|
|
- role: pihole
|
|
|
|
|
2022-04-15 15:51:58 +02:00
|
|
|
# - hosts: usg
|
|
|
|
# vars_files:
|
|
|
|
# - "vars/vault.yml"
|
|
|
|
# - "vars/wireguard.yml"
|
|
|
|
# tags: [network, ubnt]
|
|
|
|
# roles:
|
|
|
|
# - role: usg
|
|
|
|
|
|
|
|
# - hosts: cloud_key
|
|
|
|
# vars_files:
|
|
|
|
# - "vars/vault.yml"
|
|
|
|
# - "vars/wireguard.yml"
|
|
|
|
# tags: [network, ubnt]
|
|
|
|
# roles:
|
|
|
|
# - role: cloud_key
|
|
|
|
|
|
|
|
- hosts: all:!unifi
|
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:20:04 +02:00
|
|
|
tags:
|
|
|
|
- init
|
|
|
|
- update
|
2020-10-28 22:15:23 +01:00
|
|
|
vars_files:
|
|
|
|
- "vars/vault.yml"
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
# https://www.cyberciti.biz/faq/ansible-apt-update-all-packages-on-ubuntu-debian-linux/
|
|
|
|
- name: Update packages
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu'
|
2020-10-28 22:15:23 +01:00
|
|
|
ansible.builtin.apt:
|
2021-08-17 00:13:23 +02:00
|
|
|
update_cache: "True"
|
|
|
|
force_apt_get: "True"
|
2020-10-28 22:15:23 +01:00
|
|
|
cache_valid_time: 3600
|
2021-08-17 00:13:23 +02:00
|
|
|
upgrade: "True"
|
2020-10-28 22:15:23 +01:00
|
|
|
|
|
|
|
- name: Remove ubuntu motd spam
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/etc/update-motd.d/{{ item }}"
|
|
|
|
state: absent
|
|
|
|
loop:
|
|
|
|
- 10-help-text
|
2022-10-19 00:18:29 +02:00
|
|
|
- 10-uname
|
2020-10-28 22:15:23 +01:00
|
|
|
- 50-landscape-sysinfo
|
|
|
|
- 50-motd-news
|
|
|
|
- 80-livepatch
|
2022-10-18 22:20:04 +02:00
|
|
|
- 88-esm-announce
|
2021-08-17 00:13:23 +02:00
|
|
|
- 90-updates-available
|
2022-10-18 22:20:04 +02:00
|
|
|
- 91-contract-ua-esm-status
|
2022-04-15 15:51:58 +02:00
|
|
|
- 91-release-upgrade
|
2022-10-19 00:18:29 +02:00
|
|
|
- 92-unattended-upgrades
|
2020-10-28 22:15:23 +01:00
|
|
|
- 95-hwe-eol
|
2022-10-19 00:18:29 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
2020-10-28 22:15:23 +01:00
|
|
|
|
2022-10-18 22:20:04 +02:00
|
|
|
- name: Place MoTD
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2022-10-18 22:20:04 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu'
|
|
|
|
ansible.builtin.copy:
|
|
|
|
content: |
|
|
|
|
#!/bin/sh
|
|
|
|
# Ansible managed
|
|
|
|
|
|
|
|
neofetch
|
|
|
|
mode: 0755
|
|
|
|
dest: /etc/update-motd.d/01-neofetch
|
|
|
|
|
2021-08-17 00:13:23 +02:00
|
|
|
- name: Check if pi-hole is installed
|
2021-02-13 15:39:14 +01:00
|
|
|
when: inventory_hostname in groups['piholes']
|
2022-04-15 15:51:58 +02:00
|
|
|
ansible.builtin.stat:
|
2021-08-17 00:13:23 +02:00
|
|
|
path: "/usr/local/bin/pihole"
|
|
|
|
register: pihole_exec
|
|
|
|
|
|
|
|
- name: Update PiHole
|
|
|
|
when: inventory_hostname in groups['piholes'] and pihole_exec.stat.exists
|
2022-10-19 00:16:16 +02:00
|
|
|
become: "{{ do_become }}"
|
2021-02-13 15:39:14 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
argv:
|
|
|
|
- pihole
|
|
|
|
- -up
|
|
|
|
|
2022-10-19 00:18:29 +02:00
|
|
|
- name: Install and update chezmoi
|
2022-04-15 15:51:58 +02:00
|
|
|
include_tasks: tasks/omp.yml
|
|
|
|
|
|
|
|
- include_tasks: tasks/remove_prox_ee_apt.yml
|
|
|
|
when: inventory_hostname in groups['prox']
|
|
|
|
|
2020-10-28 22:15:23 +01:00
|
|
|
- name: Check if a reboot is needed for Debian and Ubuntu boxes
|
|
|
|
register: reboot_required_file
|
2022-04-15 15:51:58 +02:00
|
|
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
|
|
|
|
ansible.builtin.stat:
|
2021-08-17 00:13:23 +02:00
|
|
|
path: /var/run/reboot-required
|
|
|
|
get_md5: no
|
2020-10-28 22:15:23 +01:00
|
|
|
|
|
|
|
- name: Reboot the server
|
2021-08-17 00:13:23 +02:00
|
|
|
throttle: 1
|
2022-04-15 15:51:58 +02:00
|
|
|
when: reboot_required_file.stat.exists and (ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian')
|
2020-10-28 22:15:23 +01:00
|
|
|
ansible.builtin.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
|