Compare commits

...

5 Commits

8 changed files with 179 additions and 48 deletions

0
.codex Normal file
View File

View File

@@ -0,0 +1,16 @@
{
"name": "Ansible Development",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"features": {
"ghcr.io/devcontainers/features/ansible:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"redhat.ansible",
"ms-python.python"
]
}
},
"postCreateCommand": "pip install ansible-lint"
}

11
.vscode/settings.json vendored
View File

@@ -5,5 +5,14 @@
"envManager": "ms-python.python:venv", "envManager": "ms-python.python:venv",
"packageManager": "ms-python.python:pip" "packageManager": "ms-python.python:pip"
} }
] ],
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.pythonPath": "${workspaceFolder}/.venv/bin/python", // legacy fallback for older Python extension versions
// Keep these Ansible executable paths absolute: parts of the extension use them verbatim.
"ansible.ansiblePath": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible", // legacy fallback for older Ansible extension versions
"ansible.ansibleLintPath": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-lint", // legacy fallback for older Ansible extension versions
"ansible.ansible.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible",
"ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python3",
"ansible.validation.lint.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-lint",
"ansible.ansibleNavigator.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-navigator"
} }

View File

@@ -0,0 +1,18 @@
{
"python-envs.pythonProjects": [
{
"path": ".",
"envManager": "ms-python.python:venv",
"packageManager": "ms-python.python:pip"
}
],
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.pythonPath": "${workspaceFolder}/.venv/bin/python", // legacy fallback for older Python extension versions
// Keep these Ansible executable paths absolute: parts of the extension use them verbatim.
"ansible.ansiblePath": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible", // legacy fallback for older Ansible extension versions
"ansible.ansibleLintPath": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-lint", // legacy fallback for older Ansible extension versions
"ansible.ansible.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible",
"ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python3",
"ansible.validation.lint.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-lint",
"ansible.ansibleNavigator.path": "/home/chris/devel/git/git.oopen.de/ansible/oopen-server/.venv/bin/ansible-navigator"
}

View File

@@ -1,5 +1,4 @@
--- ---
# --- # ---
# Apache2 Server # Apache2 Server
# --- # ---
@@ -7,31 +6,29 @@
- name: Populate service facts - name: Populate service facts
ansible.builtin.service_facts: ansible.builtin.service_facts:
#- name: Print service facts # - name: Print service facts
# ansible.builtin.debug: # ansible.builtin.debug:
# var: ansible_facts.services # var: ansible_facts.services
# when: # when:
# - ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found' # - ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found'
- name: (apache2.yml) Ensure directory '/etc/systemd/system/apache2.service.d' is present - name: (apache2.yml) Ensure directory '/etc/systemd/system/apache2.service.d' is present
file: ansible.builtin.file:
path: /etc/systemd/system/apache2.service.d path: /etc/systemd/system/apache2.service.d
state: directory state: directory
owner: root owner: root
group: root group: root
mode: '0755' mode: "0755"
when: when:
- ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found' - ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found'
- name: (apache2.yml) Ensure file '/etc/systemd/system/apache2.service.d/limits.conf' exists - name: (apache2.yml) Ensure file '/etc/systemd/system/apache2.service.d/limits.conf' exists
copy: ansible.builtin.copy:
src: 'etc/systemd/system/apache2.service.d/limits.conf' src: "etc/systemd/system/apache2.service.d/limits.conf"
dest: '/etc/systemd/system/apache2.service.d/limits.conf' dest: "/etc/systemd/system/apache2.service.d/limits.conf"
owner: root owner: root
group: root group: root
mode: '0644' mode: "0644"
notify: "Restart apache2" notify: "Restart apache2"
when: when:
- ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found' - ansible_facts['services']['apache2.service']['name'] | default('not-found') != 'not-found'

View File

@@ -1,5 +1,82 @@
--- ---
- name: (cron.yml) Define candidate paths for root crontab PATH
ansible.builtin.set_fact:
cron_root_path_candidates:
- /root/bin/admin-stuff
- /root/bin
- /usr/local/apache2/bin
- /usr/local/php/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
tags:
- user_crontab
- name: (cron.yml) Check candidate paths for root crontab PATH
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ cron_root_path_candidates }}"
register: cron_root_path_stats
tags:
- user_crontab
- name: (cron.yml) Build validated root crontab PATH
ansible.builtin.set_fact:
cron_root_path: >-
{{
cron_root_path_stats.results
| selectattr('stat.exists')
| map(attribute='stat.path')
| join(':')
}}
tags:
- user_crontab
- name: (cron.yml) Check if root crontab already exists
ansible.builtin.stat:
path: /var/spool/cron/crontabs/root
register: root_crontab_file
tags:
- user_crontab
- name: (cron.yml) Initialize root crontab with default header and env vars
ansible.builtin.copy:
dest: /var/spool/cron/crontabs/root
owner: root
group: crontab
mode: '0600'
content: |
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
PATH={{ cron_root_path }}
SHELL=/bin/bash
when:
- not root_crontab_file.stat.exists
tags:
- user_crontab
- name: (cron.yml) Set env entries in user crontabs - name: (cron.yml) Set env entries in user crontabs
cron: cron:
name: '{{ item.name }}' name: '{{ item.name }}'

View File

@@ -0,0 +1,26 @@
---
- name: (extrepo.yml) Install extrepo package
ansible.builtin.apt:
name: extrepo
state: present
tags:
- extrepo
- name: (extrepo.yml) Enable contrib policy in /etc/extrepo/config.yaml
ansible.builtin.lineinfile:
path: /etc/extrepo/config.yaml
regexp: '^(#\s*)?-\s*contrib$'
insertafter: '^- main$'
line: '- contrib'
tags:
- extrepo
- name: (extrepo.yml) Enable non-free policy in /etc/extrepo/config.yaml
ansible.builtin.lineinfile:
path: /etc/extrepo/config.yaml
regexp: '^(#\s*)?-\s*non-free$'
insertafter: '^- contrib$'
line: '- non-free'
tags:
- extrepo

View File

@@ -1,8 +1,7 @@
--- ---
- import_tasks: show.yml - import_tasks: show.yml
tags: tags:
- show - show
# tags supported inside basic.yml # tags supported inside basic.yml
# #
@@ -13,7 +12,6 @@
tags: tags:
- basic - basic
# tags supported inside apt.yml # tags supported inside apt.yml
# #
# apt-update # apt-update
@@ -34,6 +32,15 @@
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: apt tags: apt
# tags supported inside extrepo.yml
#
# extrepo
- import_tasks: extrepo.yml
when:
- ansible_facts['distribution'] == "Debian"
- (ansible_facts['distribution_major_version'] | int) >= 12
tags:
- extrepo
# tags supported inside apt-gateway.yml: # tags supported inside apt-gateway.yml:
# #
@@ -44,7 +51,6 @@
- apt - apt
- apt-gateway-server - apt-gateway-server
# #
# yum-update # yum-update
# yum-base-install # yum-base-install
@@ -55,7 +61,6 @@
- ansible_facts.distribution == "CentOS" or ansible_facts.distribution == "Fedora" - ansible_facts.distribution == "CentOS" or ansible_facts.distribution == "Fedora"
tags: yum tags: yum
# tags supportetd inside caching-nameserver.yml # tags supportetd inside caching-nameserver.yml
# #
# apt-caching-nameserver # apt-caching-nameserver
@@ -65,7 +70,6 @@
when: groups['caching_nameserver']|string is search(inventory_hostname) when: groups['caching_nameserver']|string is search(inventory_hostname)
tags: caching-nameserver tags: caching-nameserver
# tags supported inside systemd-resolved.yml # tags supported inside systemd-resolved.yml
# #
# systemd-resolved # systemd-resolved
@@ -77,8 +81,6 @@
- ansible_facts['distribution_major_version'] > "11" - ansible_facts['distribution_major_version'] > "11"
- systemd_resolved is defined and systemd_resolved|bool - systemd_resolved is defined and systemd_resolved|bool
- import_tasks: tor.yml - import_tasks: tor.yml
when: when:
- inventory_hostname in groups['mail_server'] - inventory_hostname in groups['mail_server']
@@ -99,10 +101,9 @@
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- shell-config - shell-config
- vim-config - vim-config
- zsh-config - zsh-config
# tags supported inside users.yml: # tags supported inside users.yml:
# #
@@ -118,7 +119,6 @@
tags: tags:
- users - users
# tags supported inside users-systemfiles.yml: # tags supported inside users-systemfiles.yml:
# #
# bash # bash
@@ -129,7 +129,6 @@
- users - users
- users-systemfiles - users-systemfiles
# tags supported inside webadmin-user.yml: # tags supported inside webadmin-user.yml:
# #
# users-exists # users-exists
@@ -145,14 +144,12 @@
- users-systemfiles - users-systemfiles
- webadmin - webadmin
# tags supported inside sshd.yml # tags supported inside sshd.yml
# #
# sshd-config # sshd-config
- import_tasks: sshd.yml - import_tasks: sshd.yml
tags: sshd tags: sshd
# tags supported inside sudoers.yml: # tags supported inside sudoers.yml:
# #
# sudoers-remove # sudoers-remove
@@ -161,11 +158,9 @@
- import_tasks: sudoers.yml - import_tasks: sudoers.yml
tags: sudoers tags: sudoers
- import_tasks: motd.yml - import_tasks: motd.yml
tags: motd tags: motd
# tags supported inside ntp.yml: # tags supported inside ntp.yml:
# #
# ntp-server # ntp-server
@@ -175,7 +170,6 @@
when: when:
- "'lxc_guest' not in group_names" - "'lxc_guest' not in group_names"
# tags supportetd inside git.yml # tags supportetd inside git.yml
# #
# git-firewall-repository # git-firewall-repository
@@ -198,7 +192,6 @@
- import_tasks: git.yml - import_tasks: git.yml
tags: git tags: git
# tags supported inside nfs.yml: # tags supported inside nfs.yml:
# #
# nfs-server # nfs-server
@@ -207,7 +200,6 @@
tags: tags:
- nfs - nfs
# tags supported inside x2go-server.yml: # tags supported inside x2go-server.yml:
# #
# x2go-server # x2go-server
@@ -216,7 +208,6 @@
tags: tags:
- x2go - x2go
# tags supported inside copy_files.yml: # tags supported inside copy_files.yml:
# #
# copy-files # copy-files
@@ -233,7 +224,6 @@
tags: tags:
- symlink-files - symlink-files
# tags supported inside config_files_mailsystem_scripts.yml: # tags supported inside config_files_mailsystem_scripts.yml:
# #
- import_tasks: config_files_mailsystem_scripts.yml - import_tasks: config_files_mailsystem_scripts.yml
@@ -277,8 +267,8 @@
- import_tasks: redis-server.yml - import_tasks: redis-server.yml
when: inventory_hostname in groups['nextcloud_server'] or when: inventory_hostname in groups['nextcloud_server'] or
inventory_hostname in groups['apache2_webserver'] or inventory_hostname in groups['apache2_webserver'] or
inventory_hostname in groups['nginx_webserver'] inventory_hostname in groups['nginx_webserver']
tags: tags:
- redis-server - redis-server
@@ -299,10 +289,8 @@
tags: tags:
- services - services
- import_tasks: systemd-services_redhat_based_OS.yml - import_tasks: systemd-services_redhat_based_OS.yml
when: when:
- ansible_facts.os_family == "RedHat" - ansible_facts.os_family == "RedHat"
tags: tags:
- services - services