diff --git a/inventory.tmpl.ini b/inventory.tmpl.ini index 9f3ef33..72ca8c1 100644 --- a/inventory.tmpl.ini +++ b/inventory.tmpl.ini @@ -1,4 +1,4 @@ [nextcloud] -nextcloud ansible_host={{INSTANCE}} ansible_user=ubuntu +nextcloud ansible_host={{INSTANCE}} ansible_user=ubuntu hostname=nextcloud [nextcloud:vars] ansible_ssh_common_args=-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand="sh -c \"aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p\"" diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml new file mode 100644 index 0000000..57b6b31 --- /dev/null +++ b/roles/common/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: reboot + reboot: + reboot_timeout: 3600 + diff --git a/roles/common/tasks/main.yaml b/roles/common/tasks/main.yaml new file mode 100644 index 0000000..dea1a3b --- /dev/null +++ b/roles/common/tasks/main.yaml @@ -0,0 +1,67 @@ +--- + +# configure system + +- name: Configure hostname + copy: + content: "{{ hostname }}" + dest: /etc/hostname + notify: reboot +# yep we reboot for this + +- name: hostname in hosts + lineinfile: + path: /etc/hosts + regexp: "^127.0.0.1" + line: "127.0.0.1 {{ hostname }} localhost" + +- name: Set timezone + file: + src: /usr/share/zoneinfo/America/Los_Angeles + dest: /etc/localtime + state: link + notify: reboot + +- name: Set keyboard + lineinfile: + path: /etc/default/keyboard + regexp: '^XKBLAYOUT=' + line: 'XKBLAYOUT="us"' + notify: reboot + +- name: Shaboom!!! + apt: + update_cache: yes + upgrade: dist + force_apt_get: yes + retries: 2 + delay: 10 + +- name: install base apps + apt: + force_apt_get: yes + name: + - vim + - less + - tmux + - telnet + - ntp + - lsof + +- name: edit bashrc + blockinfile: + path: /etc/bash.bashrc + marker: "### {mark} ANSIBLE MANAGED BLOCK {{ item.name }} ###" + block: "{{ item.block }}" + with_items: + - name: prompt + block: | + if [[ $USER == 'root' ]]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]# ' + else + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;32m\]\w\[\033[00m\]\$ ' + fi + - name: lscolor + block: | + alias ls='ls --color=auto' + diff --git a/roles/common/templates/rpi_custom_exporter.service b/roles/common/templates/rpi_custom_exporter.service new file mode 100644 index 0000000..9a5cb1b --- /dev/null +++ b/roles/common/templates/rpi_custom_exporter.service @@ -0,0 +1,11 @@ + +[Unit] +Description=Pi4 custom collector +After=network.target + +[Service] +ExecStart=/srv/rpi_custom_exporter/exporter.py +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/roles/common/templates/rpi_exporter.py b/roles/common/templates/rpi_exporter.py new file mode 100644 index 0000000..262e27d --- /dev/null +++ b/roles/common/templates/rpi_exporter.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +import time +from prometheus_client.core import GaugeMetricFamily, REGISTRY, CounterMetricFamily +from prometheus_client import start_http_server +from gpiozero import CPUTemperature + +class CustomCollector(object): + def __init__(self): + pass + + def collect(self): + val = CPUTemperature() + t = GaugeMetricFamily("rpi_cpu_temperature", "CPU Temperature", labels=['instance']) + t.add_metric(['C'], val.temperature) + yield t + + f = GaugeMetricFamily("rpi_cpu_temperature_f", "CPU Temperature", labels=['instance']) + f.add_metric(['F'], val.temperature * (9.0/5.0) + 32) + yield t + +if __name__ == '__main__': + start_http_server(7998) + REGISTRY.register(CustomCollector()) + while True: + time.sleep(1) diff --git a/roles/common/templates/rsyslog-rng.conf b/roles/common/templates/rsyslog-rng.conf new file mode 100644 index 0000000..165dd19 --- /dev/null +++ b/roles/common/templates/rsyslog-rng.conf @@ -0,0 +1,2 @@ +:programname,startswith,"rng" /dev/null +:programname,startswith,"rng" stop diff --git a/roles/nextcloud/tasks/main.yaml b/roles/nextcloud/tasks/main.yaml index 03941d6..d2c1b7f 100644 --- a/roles/nextcloud/tasks/main.yaml +++ b/roles/nextcloud/tasks/main.yaml @@ -8,3 +8,26 @@ - db - data +- name: install docker + apt: + force_apt_get: yes + name: "{{ packages }}" + vars: + packages: + - docker.io + - docker-compose + +- name: Add users to docker group + user: + name: "{{ item }}" + groups: docker + append: yes + with_items: + - ubuntu + +- name: do some cleanup + command: "{{item}}" + with_items: + - "docker image prune -a --force" + - "docker system prune --volumes --force" + diff --git a/site.yaml b/site.yaml index a7be44b..07a535e 100644 --- a/site.yaml +++ b/site.yaml @@ -3,6 +3,11 @@ #- name: get environment # ec2_metadata_facts: +- name: apply common config + hosts: all + roles: + - { role: common, become: yes } + - name: setup nextcloud instance hosts: nextcloud roles: