diff --git a/hello.yml b/hello.yml new file mode 100644 index 0000000..2f9e11e --- /dev/null +++ b/hello.yml @@ -0,0 +1,7 @@ +- name: Moin Hello World + hosts: all + tasks: + - name: Moin Hello Message + debug: + msg: "Moin! Hello World!" + diff --git a/inventories/inventory_home b/inventories/inventory_home new file mode 100644 index 0000000..7626d13 --- /dev/null +++ b/inventories/inventory_home @@ -0,0 +1,9 @@ +--- +all: + hosts: + raspberrypi1.seboto.net: + raspberrypi2.seboto.net: + raspberrypi3.seboto.net: + raspberrypi4.seboto.net: + raspberrypi5.seboto.net: +... diff --git a/inventories/inventory_home.yml b/inventories/inventory_home.yml new file mode 100644 index 0000000..7626d13 --- /dev/null +++ b/inventories/inventory_home.yml @@ -0,0 +1,9 @@ +--- +all: + hosts: + raspberrypi1.seboto.net: + raspberrypi2.seboto.net: + raspberrypi3.seboto.net: + raspberrypi4.seboto.net: + raspberrypi5.seboto.net: +... diff --git a/inventories/inventory_jens b/inventories/inventory_jens new file mode 100644 index 0000000..90908d7 --- /dev/null +++ b/inventories/inventory_jens @@ -0,0 +1,31 @@ +--- +all: + hosts: + server1.seboto.net: + ansible_user: jens + children: + seboto: + hosts: + srv1.seboto.de: + srv2.seboto.de: + srv3.seboto.de: + pi: + hosts: + raspberrypi1.seboto.net: + ansible_user: pi + raspberrypi2.seboto.net: + ansible_user: pi + raspberrypi3.seboto.net: + ansible_user: pi + raspberrypi4.seboto.net: + ansible_user: pi + raspberrypi5.seboto.net: + ansible_user: pi + vip: + hosts: + srv2.seboto.de: + raspberrypi3.seboto.net: + ansible_user: pi + vars: + ansible_python_interpreter: /usr/bin/python3 +... diff --git a/inventories/inventory_seboto b/inventories/inventory_seboto new file mode 100644 index 0000000..545871f --- /dev/null +++ b/inventories/inventory_seboto @@ -0,0 +1,7 @@ +--- +all: + hosts: + srv1.seboto.de: + srv2.seboto.de: + srv3.seboto.de: +... diff --git a/pkg_upgrade.yml b/pkg_upgrade.yml new file mode 100644 index 0000000..32b6ad3 --- /dev/null +++ b/pkg_upgrade.yml @@ -0,0 +1,50 @@ +--- +- name: Linux Package Upgrade + hosts: all + remote_user: root + tasks: + - name: "[Debian] Refresh Package Cache if not older that 1h" + apt: + update_cache: yes + cache_valid_time: 3600 + become: true + when: ansible_os_family == "Debian" + + - name: "[AlmaLinux] Refresh Package Cache if not older that 1h" + dnf: + update_cache: yes + become: true + when: ansible_os_family == "AlmaLinux" + + - name: "[Debian] Remove Packages that can no longer be downloaded" + apt: + autoclean: yes + become: true + when: ansible_os_family == "Debian" + + - name: "[Debian] Remove packages that are no longer required" + apt: + autoremove: yes + become: true + when: ansible_os_family == "Debian" + + - name: "[AlmaLinux] Remove packages that are no longer required" + dnf: + autoremove: yes + become: true + when: ansible_os_family == "AlmaLinux" + + - name: "[Debian] Upgrade all packages that need an update" + apt: + upgrade: full + become: true + when: ansible_os_family == "Debian" + + - name: "[AlmaLinux] Upgrade all packages that need an update" + dnf: + name: "*" + state: latest + become: true + when: ansible_os_family == "AlmaLinux" +... + diff --git a/playbooks/hello.yml b/playbooks/hello.yml new file mode 100644 index 0000000..2f9e11e --- /dev/null +++ b/playbooks/hello.yml @@ -0,0 +1,7 @@ +- name: Moin Hello World + hosts: all + tasks: + - name: Moin Hello Message + debug: + msg: "Moin! Hello World!" + diff --git a/playbooks/pkg_upgrade.yml b/playbooks/pkg_upgrade.yml new file mode 100644 index 0000000..2f7c534 --- /dev/null +++ b/playbooks/pkg_upgrade.yml @@ -0,0 +1,27 @@ +--- +- name: Linux Package Upgrade + hosts: all + remote_user: root + tasks: + - name: Refresh Package Cache if not older that 1h + apt: + update_cache: yes + cache_valid_time: 3600 + become: true + + - name: Remove Packages that can no longer be downloaded + apt: + autoclean: yes + become: true + + - name: Remove packages that are no longer required + apt: + autoremove: yes + become: true + + - name: Upgrade all packages that need an update + apt: + upgrade: full + become: true +... + diff --git a/playbooks/reboot.yml b/playbooks/reboot.yml new file mode 100644 index 0000000..a7995c3 --- /dev/null +++ b/playbooks/reboot.yml @@ -0,0 +1,27 @@ +--- +- name: Reboot host + hosts: all + remote_user: root + tasks: + - name: reboot host + shell: 'sleep 5 && shutdown -r now "Reboot by Ansible."' + register: reboot + async: 1 + poll: 0 + ignore_errors: true + + - name: wait for server to come down + local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped + + - name: wait for server to come up + local_action: wait_for host={{ inventory_hostname }} port=22 state=started + + - name: check uptime + shell: 'uptime' + register: uptime + + - name: show uptime + debug: + msg: "Uptime: {{ uptime.stdout }}" +... + diff --git a/playbooks/reboot_required.yml b/playbooks/reboot_required.yml new file mode 100644 index 0000000..72d6ea6 --- /dev/null +++ b/playbooks/reboot_required.yml @@ -0,0 +1,39 @@ +--- +- name: Reboot host + hosts: all + remote_user: root + tasks: + - name: check if reboot is required + stat: + path: /lib/modules/{{ ansible_kernel }} + register: modules + + - name: reboot host + shell: 'sleep 5 && shutdown -r now "Reboot by Ansible."' + register: reboot + async: 1 + poll: 0 + ignore_errors: true + when: modules.stat.isdir is not defined + + - name: wait for server to come down + local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped + when: + - reboot.stdout is defined + - "'Reboot by Ansible.' in reboot.stdout" + + - name: wait for server to come up + local_action: wait_for host={{ inventory_hostname }} port=22 state=started + when: + - reboot.stdout is defined + - "'Reboot by Ansible.' in reboot.stdout" + + - name: check uptime + shell: 'uptime' + register: uptime + + - name: show uptime + debug: + msg: "Uptime: {{ uptime.stdout }}" +... + diff --git a/playbooks/roles b/playbooks/roles new file mode 120000 index 0000000..d8c4472 --- /dev/null +++ b/playbooks/roles @@ -0,0 +1 @@ +../roles \ No newline at end of file diff --git a/playbooks/setup_awx.yml b/playbooks/setup_awx.yml new file mode 100644 index 0000000..23d84d8 --- /dev/null +++ b/playbooks/setup_awx.yml @@ -0,0 +1,7 @@ +--- +- name: setup AWX + hosts: server1.seboto.net + remote_user: root + roles: + - awx +... diff --git a/playbooks/test.txt b/playbooks/test.txt new file mode 100644 index 0000000..6de7b8c --- /dev/null +++ b/playbooks/test.txt @@ -0,0 +1 @@ +This is a test file. diff --git a/playbooks/test.yml b/playbooks/test.yml new file mode 100644 index 0000000..f11b022 --- /dev/null +++ b/playbooks/test.yml @@ -0,0 +1,15 @@ +--- +- name: Moin Hello World + hosts: all + tasks: + - name: Moin Hello Message + debug: + msg: "Moin! Hello World!" + - name: Copy File + copy: + src: test.txt + dest: /tmp/test_{{ ansible_hostname }}.txt + mode: "0644" + owner: jens + group: users +... diff --git a/reboot.yml b/reboot.yml new file mode 100644 index 0000000..a7995c3 --- /dev/null +++ b/reboot.yml @@ -0,0 +1,27 @@ +--- +- name: Reboot host + hosts: all + remote_user: root + tasks: + - name: reboot host + shell: 'sleep 5 && shutdown -r now "Reboot by Ansible."' + register: reboot + async: 1 + poll: 0 + ignore_errors: true + + - name: wait for server to come down + local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped + + - name: wait for server to come up + local_action: wait_for host={{ inventory_hostname }} port=22 state=started + + - name: check uptime + shell: 'uptime' + register: uptime + + - name: show uptime + debug: + msg: "Uptime: {{ uptime.stdout }}" +... + diff --git a/reboot_required.yml b/reboot_required.yml new file mode 100644 index 0000000..72d6ea6 --- /dev/null +++ b/reboot_required.yml @@ -0,0 +1,39 @@ +--- +- name: Reboot host + hosts: all + remote_user: root + tasks: + - name: check if reboot is required + stat: + path: /lib/modules/{{ ansible_kernel }} + register: modules + + - name: reboot host + shell: 'sleep 5 && shutdown -r now "Reboot by Ansible."' + register: reboot + async: 1 + poll: 0 + ignore_errors: true + when: modules.stat.isdir is not defined + + - name: wait for server to come down + local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped + when: + - reboot.stdout is defined + - "'Reboot by Ansible.' in reboot.stdout" + + - name: wait for server to come up + local_action: wait_for host={{ inventory_hostname }} port=22 state=started + when: + - reboot.stdout is defined + - "'Reboot by Ansible.' in reboot.stdout" + + - name: check uptime + shell: 'uptime' + register: uptime + + - name: show uptime + debug: + msg: "Uptime: {{ uptime.stdout }}" +... + diff --git a/roles/awx/defaults/main.yml b/roles/awx/defaults/main.yml new file mode 100644 index 0000000..82a8c19 --- /dev/null +++ b/roles/awx/defaults/main.yml @@ -0,0 +1,74 @@ +--- +# +# AWX version and base directory to deploy the Git Repo +# +awx_version: 19.2.0 +awx_basedir: /opt/awx +awx_github_repo: https://github.com/ansible/awx.git +# +# directory and names of files for the docker-compose project +# +awx_composedir: /opt/awxcompose{{ awx_version }} +awx_compose_name: 'docker-compose.yml' +awx_compose_override_name: 'docker-compose.override.yml' +awx_prefix: "awx{{ awx_version.split('.') | join }}" +# +# Propeties of UNIX User awx +# +awx_user: awx +awx_group: docker +awx_password: '%a1W2x3$' +# +# Flag to force a deployment if already deployed +# +awx_force_deployment: False +# +# Flag to keep local data when awx_force_deployment is set to True +# +awx_keep_existing: False +# +# Flag to disable active Schedules in AWX database +# +disable_schedule: True +# +# Build User Interface +# Remark: Must be run atleast once +# +build_ui: True +# +# Build and Push Docker Image +# Remark: Build of the Docker image is required before running a new AWX version +# +build_docker_image: True +push_docker_image: True +# +# Name and version of the Docker image +# +awx_image: "{{ docker_registry }}/awx/awx_devel" +awx_image_tag: "{{ awx_version }}" +# +# PostgreSQL settings +# +pg_port: 5432 +pg_username: 'awxuser' +pg_database: 'awx' +pg_password: 'awxpassw0rd' +# +# Number of AWX containers. If set to 1, no haproxy is deployed +# +cluster_node_count: 1 +traefik_http_port: 8013 +http_port: 8013 +https_port: 8043 +sdb_port_base: 15899 +#database_dump_file: pg_dumpall_awx_17.1.0_2021-05-30_23.00.01.sql.gz +database_dump_file: pg_dump_awx_2021-06-09_11.23.45.sql.gz +docker_registry: pi4.seboto.net:50000 +# +# AWX Host for Traefik +# +awx_traefik_host: "awx{{ awx_version.split('.') | join }}.seboto.ma-wan.de" +awx_traefik_sans: + - "ansible{{ awx_version.split('.') | join }}.seboto.ma-wan.de" + +... diff --git a/roles/awx/files/HouseKeeping.sh b/roles/awx/files/HouseKeeping.sh new file mode 100755 index 0000000..4e9c156 --- /dev/null +++ b/roles/awx/files/HouseKeeping.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# +# This script will clean up a directory from old files. +# +# Options: +# -d +# -t