From ade7fd30f42119758bdc0245b351d6df389cefaa Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 9 Oct 2022 18:51:41 -0400 Subject: [PATCH] Add an initial sudo role. --- ansible/ansible.cfg | 2 ++ .../environments/home/host_vars/homeserver | 1 + ansible/environments/home/hosts | 2 ++ ansible/playbook.yaml | 5 ++++ ansible/roles/sudo/tasks/main.yaml | 5 ++++ ansible/run.bash | 25 +++++++++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 ansible/ansible.cfg create mode 100644 ansible/environments/home/host_vars/homeserver create mode 100644 ansible/environments/home/hosts create mode 100644 ansible/playbook.yaml create mode 100644 ansible/roles/sudo/tasks/main.yaml create mode 100755 ansible/run.bash diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..8f5d8d2 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +pipelining = True diff --git a/ansible/environments/home/host_vars/homeserver b/ansible/environments/home/host_vars/homeserver new file mode 100644 index 0000000..c42fd44 --- /dev/null +++ b/ansible/environments/home/host_vars/homeserver @@ -0,0 +1 @@ +os_flavor: "FreeBSD" diff --git a/ansible/environments/home/hosts b/ansible/environments/home/hosts new file mode 100644 index 0000000..41c1e9e --- /dev/null +++ b/ansible/environments/home/hosts @@ -0,0 +1,2 @@ +[headless] +homeserver ansible_user=talexander ansible_host=192.168.1.215 diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml new file mode 100644 index 0000000..dfadbd7 --- /dev/null +++ b/ansible/playbook.yaml @@ -0,0 +1,5 @@ +- hosts: all + vars: + ansible_become: True + roles: + - sudo diff --git a/ansible/roles/sudo/tasks/main.yaml b/ansible/roles/sudo/tasks/main.yaml new file mode 100644 index 0000000..e9e7582 --- /dev/null +++ b/ansible/roles/sudo/tasks/main.yaml @@ -0,0 +1,5 @@ +- name: Install packages + package: + name: + - sudo + state: present diff --git a/ansible/run.bash b/ansible/run.bash new file mode 100755 index 0000000..a6ec49e --- /dev/null +++ b/ansible/run.bash @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# Run ansible +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR" + +function die { + code="$1" + shift 1 + (>&2 echo "${@}") + exit "$code" +} + +target="$1" +shift 1 + +if [ "$target" = "homeserver" ]; then + ansible-playbook -v -i environments/home playbook.yaml --diff --limit homeserver "${@}" +elif [ "$target" = "dummy" ]; then + echo "dummy" +else + die 1 "Unrecognized target" +fi