Skip to content

Commit

Permalink
Adjusted ansible inventory to satisfy ansible-lint, updated submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
felbinger committed Aug 27, 2023
1 parent 9596f10 commit e889f0b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 46 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/gitops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ on:
push:
branches: [main]
pull_request:
schedule:
- cron: '53 1 */15 * *'
# schedule:
# - cron: '53 1 */15 * *'

jobs:
lint:
runs-on: ubuntu-latest
container:
image: ghcr.io/ansible/creator-ee
image: ghcr.io/secshellnet/ansible-creator-ee # ghcr.io/ansible/creator-ee with preinstalled collections

steps:
- uses: actions/checkout@v3

- name: Run ansible-lint
run: |
ansible-lint -x yaml[comments],yaml[empty-lines],\
yaml[new-line-at-end-of-file],yaml[trailing-spaces],\
var-spacing,command-instead-of-shell,no-changed-when,\
name[template],args[module]
ansible-lint -x command-instead-of-shell,no-changed-when,\
name[template],jinja[invalid]
run:
runs-on: ubuntu-latest
needs: [lint]
# needs: [lint]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion inventory.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
all:
hosts:
hosts:
64 changes: 36 additions & 28 deletions playbook.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
- hosts: all
- name: "Play to create hetzner cloud servers"
hosts: all
connection: local
gather_facts: false

tasks:
- ansible.builtin.include_tasks: "tasks/hetzner-cloud.yaml"
- name: "Interact with hcloud to create cloud servers"
ansible.builtin.include_tasks: "tasks/hetzner-cloud.yaml"

- hosts: all
- name: "Play to configure servers"
hosts: all
tasks:
- ansible.builtin.include_tasks: "tasks/create-worker-user.yaml"
- name: "Create low privileged user account"
ansible.builtin.include_tasks: "tasks/create-worker-user.yaml"

- name: "Remove labels from cloud server {{ inventory_hostname }}"
hetzner.hcloud.hcloud_server:
Expand All @@ -21,12 +25,13 @@
when: new_server
delegate_to: localhost

- ansible.builtin.include_role:
name: "roles/ansible-role-sshd"
- name: "Configure sshd"
ansible.builtin.include_role:
name: "ansible-role-sshd"

- name: "Update repositories cache on systems using apt"
ansible.builtin.apt:
update_cache: yes
update_cache: true
when: ansible_pkg_mgr == 'apt'
changed_when: false
become: true
Expand All @@ -38,30 +43,33 @@
when: "ansible_distribution in ['CentOS', 'AlmaLinux', 'Rocky']"
become: true

- ansible.builtin.include_role:
name: "roles/ansible-role-fail2ban"
- name: "Setup fail2ban"
ansible.builtin.include_role:
name: "ansible-role-fail2ban"

- ansible.builtin.include_tasks: "tasks/auto-update.yaml"
- name: "Configure automatic updates of installed packages"
ansible.builtin.include_tasks: "tasks/auto-update.yaml"

#- name: "Install unattended upgrades"
# ansible.builtin.apt:
# name:
# - python3-requests
# - python3-apt
# - curl
# - wget
# - dnsutils
# - mtr
# - tcpdump
# - ncdu
# - jq
# - iptables
# - iptables-persistent
# state: present
# become: true
# - name: "Install unattended upgrades"
# ansible.builtin.apt:
# name:
# - python3-requests
# - python3-apt
# - curl
# - wget
# - dnsutils
# - mtr
# - tcpdump
# - ncdu
# - jq
# - iptables
# - iptables-persistent
# state: present
# become: true

- ansible.builtin.include_role:
name: "roles/ansible-role-nginx"
- name: "Setup nginx"
ansible.builtin.include_role:
name: "ansible-role-nginx"
when:
- enable_ipv4 # otherwise acme.sh cannot be installed
- install_nginx
2 changes: 1 addition & 1 deletion roles/ansible-role-fail2ban
2 changes: 1 addition & 1 deletion roles/ansible-role-sshd
5 changes: 3 additions & 2 deletions tasks/auto-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

- name: "Create dnf-automatic configuration file"
ansible.builtin.template:
src: ../templates/dnf-automatic.conf.j2
src: dnf-automatic.conf.j2
dest: /etc/dnf/dnf-automatic.conf
mode: "0644"
become: true

- name: "Enable and start dnf-automatic timer"
ansible.builtin.systemd:
name: dnf-automatic.timer
enabled: yes
enabled: true
state: started
become: true
4 changes: 2 additions & 2 deletions tasks/create-worker-user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ansible.builtin.user:
name: "{{ worker_user }}"
password: "{{ worker_password | password_hash('sha512') }}"
password_lock: no
password_lock: false
when: new_server

- name: "Ensure .ssh directory exists for {{ worker_user }}"
Expand All @@ -30,4 +30,4 @@
owner: "{{ worker_user }}"
group: "{{ worker_user }}"
mode: "0600"
become: true
become: true
4 changes: 2 additions & 2 deletions tasks/hetzner-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
ansible.builtin.set_fact:
new_server: "{{ 'new' in server_info.labels }}"

# when multiple hosts are defined the add_host task doesn't work as I was expecting
# it before that's why I decided to run the job only once, loop over all hosts
# when multiple hosts are defined the add_host task doesn't work as I was expecting
# it before that's why I decided to run the job only once, loop over all hosts
# and access the host variables using: vars['hostvars'][item]
- name: "Adjust inventory entries"
ansible.builtin.add_host:
Expand Down

0 comments on commit e889f0b

Please sign in to comment.