From 6e5d19ecfa225c1e25d6354cf59c3937356d8414 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Tue, 14 Oct 2025 19:02:36 +0200 Subject: [PATCH] write ansible --- slides/ansible/ansible.md | 226 +++++++++++++++++++++++ slides/ansible/examples/bind.yml | 22 +++ slides/ansible/examples/mmcli.yml | 27 +++ slides/ansible/examples/tlmgr.yml | 10 + slides/ansible/examples/transmission.yml | 18 ++ slides/ansible/examples/tspreed.yml | 24 +++ 6 files changed, 327 insertions(+) create mode 100644 slides/ansible/ansible.md create mode 100644 slides/ansible/examples/bind.yml create mode 100644 slides/ansible/examples/mmcli.yml create mode 100644 slides/ansible/examples/tlmgr.yml create mode 100644 slides/ansible/examples/transmission.yml create mode 100644 slides/ansible/examples/tspreed.yml diff --git a/slides/ansible/ansible.md b/slides/ansible/ansible.md new file mode 100644 index 0000000..6b8a870 --- /dev/null +++ b/slides/ansible/ansible.md @@ -0,0 +1,226 @@ +--- +title: Ansible +author: Malin +theme: Warsaw +colortheme: orchid +--- + +# First: Idempotence + +## My Setup Script + + +```sh +# Place locale info +echo 'LANG=en_GB.UTF-8' >> /etc/locale.conf +/etc/default/libc-locales +xbps-reconfigure -fy glibc-locales + +# Start cron service +xbps-install -y crontab +ln -s /etc/sv/cronie /var/service +sv start crontab + +# Add default dot files +git clone https://gitlab.com/andonome/mkdots.git /etc/skel/.dots + +useradd -m ghost +usermod -aG wheel + +``` + +*** + +> Error: no package 'cron tab' + +*** + +```sh +# Place locale info +echo 'LANG=en_GB.UTF-8' >> /etc/locale.conf +/etc/default/libc-locales +xbps-reconfigure -fy glibc-locales + +# Start cron service +xbps-install -y cronie +ln -s /etc/sv/cronie /var/service +sv start cronie + +# Add default dot files +git clone https://gitlab.com/andonome/mkdots.git /etc/skel/.dots + +useradd -m ghost +usermod -aG wheel + +``` + +> ...loading locales + +*** + +> Error: No command 'git' +> Error: user already exists + +*** + +```sh +# Place locale info +echo 'LANG=en_GB.UTF-8' >> /etc/locale.conf +/etc/default/libc-locales +xbps-reconfigure -fy glibc-locales + +# Start cron service +xbps-install -y cronie git +ln -s /etc/sv/cronie /var/service +sv start cronie + +# Add default dot files +git clone https://gitlab.com/andonome/mkdots.git /etc/skel/.dots + +useradd -m ghost +usermod -G wheel + +``` + +*** + +> `$ cat /etc/locale.conf` + +```sh +LC_COLLATE=C +LANG=en_GB.UTF-8 +LANG=en_GB.UTF-8 +LANG=en_GB.UTF-8 +LANG=en_GB.UTF-8 +LANG=en_GB.UTF-8 +LANG=en_GB.UTF-8 +``` + +> `$ ???` + +*** + + +```sh +grep en_GB /etc/locale.conf || \ + echo 'LANG=en_GB.UTF-8' >> /etc/locale.conf + +``` + +*** + +# So Ansible... + + +```sh +ansible --module-name=ping localhost +ansible -m package -a 'upgrade=yes' localhost +``` + +## Lines in Files + +```sh +ansible -m lineinfile -a 'line=test create=yes path=/tmp/x' localhost +ansible -m say -a 'voice=en_GB msg="Testing"' localhost +ansible -m say -a 'voice=en_GB msg="Testing"' localhost +``` + +*** + +# More Hosts! + +Hark at the hosts in `~/.ssh/config`: + +```sh +Host soft + HostName soft.dmz.rs + Port 2222 + User ghost + IdentityFile ~/.ssh/id_rsa +Host krov + HostName krov.dmz.rs + User malin +Host kralizec + HostName dmz.rs + User root +Host laka + HostName 192.168.0.50 + IdentityFile ~/.ssh/id_rsa +``` + +*** + +## Hosts in toml + + +```toml +[webby] +nginx12 + +[webby:vars] +user=alice +``` + +This is easy to read, but breaks standards. + +*** + +`ansible-play -i hosts.toml playbooks/mmcli` + +*** + +Better to stick with standards, even if you can't read it! + +*** + +Very yaml: + +```yml +all: + vars: + ansible_python_interpreter: /usr/bin/python3.13 + cow_selection: random + username: ghost + locale: Europe/Belgrade + libc_locale: en_GB.UTF-8 UTF-8 + children: + arch: + children: + archyay: + hosts: + ratking: + archkube: + nimbus: + void: + hosts: + hex: + debian: + vars: + ansible_python_interpreter: /usr/bin/python3.12 + hosts: + laka: + proxmox: + +``` + +*** + +`ansible-play -i hosts.yml playbooks/mmcli` + +*** + +# What it Does + +- Installs packages +- Copies configs *to* host +- Fetches files *from* host + * Backup ssl certs + * Backup ssh identify keys + +*** + +# Check the Repository Here! + +`[ $git_repo_address ]` + + diff --git a/slides/ansible/examples/bind.yml b/slides/ansible/examples/bind.yml new file mode 100644 index 0000000..f0cec3c --- /dev/null +++ b/slides/ansible/examples/bind.yml @@ -0,0 +1,22 @@ +--- +- name: Compile BIND + hosts: hex + become: false + environment: + PATH: '{{ ansible_env.PATH }}' + + tasks: + - name: Git pull BIND + ansible.builtin.git: + repo: https://gitlab.com/bindrpg/core.git + dest: "{{ ansible_user_dir }}/core" + clone: true + verify_commit: true + version: master + + + - name: Make BIND + community.general.make: + chdir: "{{ ansible_user_dir }}/core" + jobs: 3 + target: all diff --git a/slides/ansible/examples/mmcli.yml b/slides/ansible/examples/mmcli.yml new file mode 100644 index 0000000..56a4bca --- /dev/null +++ b/slides/ansible/examples/mmcli.yml @@ -0,0 +1,27 @@ +--- +- name: Install Mermaid ASCII + hosts: laka + become: true + + tasks: + - name: Install deps + ansible.builtin.package: + name: + - git + - golang + - make + + - name: Ensure local src dir exists + ansible.builtin.file: + path: /usr/local/src/ + state: directory + mode: '0755' + - name: Clone mermaid-ascii + ansible.builtin.git: + repo: https://github.com/AlexanderGrooff/mermaid-ascii.git + dest: /usr/local/src/mermaid-ascii/ + update: yes + - name: Install mermaid + community.general.make: + chdir: /usr/local/src/mermaid-ascii/ + target: install diff --git a/slides/ansible/examples/tlmgr.yml b/slides/ansible/examples/tlmgr.yml new file mode 100644 index 0000000..61dfce1 --- /dev/null +++ b/slides/ansible/examples/tlmgr.yml @@ -0,0 +1,10 @@ +--- +- name: Install tlmgr + hosts: june + become: true + + tasks: + - name: Install texlive + ansible.builtin.script: mintex.sh + args: + creates: /usr/local/bin/tlmgr diff --git a/slides/ansible/examples/transmission.yml b/slides/ansible/examples/transmission.yml new file mode 100644 index 0000000..3750abb --- /dev/null +++ b/slides/ansible/examples/transmission.yml @@ -0,0 +1,18 @@ +--- +- name: Make crontab + hosts: june + become: true + + tasks: + - name: Late-night transmission start + ansible.builtin.cron: + name: start transmission + minute: 0 + hour: 3 + job: /usr/bin/systemctl start transmission + - name: Late-night transmission end + ansible.builtin.cron: + name: stop transmission + minute: 0 + hour: 6 + job: /usr/bin/systemctl stop transmission diff --git a/slides/ansible/examples/tspreed.yml b/slides/ansible/examples/tspreed.yml new file mode 100644 index 0000000..8c0eb21 --- /dev/null +++ b/slides/ansible/examples/tspreed.yml @@ -0,0 +1,24 @@ +--- +- name: Install tspreed + hosts: october + become: true + + tasks: + - name: Ensure local src dir exists + ansible.builtin.file: + path: /usr/local/src/ + state: directory + mode: '0755' + - name: Install make + ansible.builtin.package: + name: make + state: present + - name: Clone tspreed + ansible.builtin.git: + repo: https://github.com/n-ivkovic/tspreed.git + dest: /usr/local/src/tspreed + update: yes + - name: Install tspreed + community.general.make: + chdir: /usr/local/src/tspreed + target: install