From 817e41ebe1bb219505a48f8a6f3c7e4725817729 Mon Sep 17 00:00:00 2001 From: Krispin Date: Fri, 9 Feb 2024 16:49:40 +0100 Subject: [PATCH] add mosquitto to ansible --- Makefile | 10 ++++++-- ansible/environments/prod/hosts.yaml | 9 +++++-- ansible/environments/prod/secrets.yaml | 13 ++++++---- ansible/roles/mosquitto/files/mosquitto.conf | 0 ansible/roles/mosquitto/handlers/main.yml | 25 ++++++++++++++++++++ ansible/roles/mosquitto/tasks/main.yml | 19 +++++++++++++++ ansible/setup.yaml | 10 +++++++- 7 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 ansible/roles/mosquitto/files/mosquitto.conf create mode 100644 ansible/roles/mosquitto/handlers/main.yml create mode 100644 ansible/roles/mosquitto/tasks/main.yml diff --git a/Makefile b/Makefile index 1ad7553..0664bd2 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ help: ## Show help for this Makefile up: .env ## Start local dev environment with docker-compose @docker-compose -p "${PROJECT}" up --force-recreate +down: .env ## Stop local dev environment with docker-compose + @docker-compose -p "${PROJECT}" down + ansible-requirements: ## Install ansible requirements via ansible-galaxy. ansible-galaxy collection install -r ./ansible/requirements.yaml ansible-galaxy role install -r ./ansible/requirements.yaml @@ -47,8 +50,11 @@ deploy: ## Deploy fabaccess with ansible. -i "./ansible/environments/${ENVIRONMENT}" \ ansible/deploy.yaml -secrets-encrypt: ## Encrypt secrets with ansible-vault +secrets-edit: ## Edit secrets with ansible-vault. + ansible-vault edit --vault-id "${ENVIRONMENT}@prompt" "./ansible/environments/${ENVIRONMENT}/secrets.yaml" + +secrets-encrypt: ## Encrypt secrets with ansible-vault. ansible-vault encrypt --vault-id "${ENVIRONMENT}@prompt" "./ansible/environments/${ENVIRONMENT}/secrets.yaml" -secrets-decrypt: ## Decrypt secrets with ansible-vault +secrets-decrypt: ## Decrypt secrets with ansible-vault. ansible-vault decrypt --vault-id "${ENVIRONMENT}@prompt" "./ansible/environments/${ENVIRONMENT}/secrets.yaml" \ No newline at end of file diff --git a/ansible/environments/prod/hosts.yaml b/ansible/environments/prod/hosts.yaml index e687c2b..cb1f261 100644 --- a/ansible/environments/prod/hosts.yaml +++ b/ansible/environments/prod/hosts.yaml @@ -2,5 +2,10 @@ all: hosts: oklab: ansible_connection: paramiko - ansible_user: ok - ansible_host: "{{OKLAB_HOST}}" \ No newline at end of file + ansible_user: "{{OKLAB_USER}}" + ansible_become_password: "{{OKLAB_PASSWORD}}" + ansible_host: "{{OKLAB_HOST}}" + +mosquitto: + hosts: + oklab: \ No newline at end of file diff --git a/ansible/environments/prod/secrets.yaml b/ansible/environments/prod/secrets.yaml index 0937030..908d521 100644 --- a/ansible/environments/prod/secrets.yaml +++ b/ansible/environments/prod/secrets.yaml @@ -1,6 +1,9 @@ $ANSIBLE_VAULT;1.2;AES256;prod -61653263353331653236653638643639386461613865636332613831643263663831393335373763 -3833326161323931303962393738383364346365313365650a373766383132653539306331396634 -65333138323536336432353565373064316663366363666661623939386663633232383832336261 -3532616566343135300a383232356438313138396530663832383531343161626336363430343762 -39326432613634346164386338386365356366316265373237316566383562663932 +61313036643561666239323562303433363563386465383930646261656637663166383235636663 +3263616539353535363134633034353831343834383731370a316339313861393036636263663663 +34306533303231333039363031616335626338643563663037326365353838643261633366396436 +6231643036653531380a613235346266353465623466306263336137633066326565373138386166 +37653135313364353131393330353631646338623461663637373864306230353166303761326439 +35306139663463373762646463353734323361613737666436643563313866613837643962356636 +30613965653561336235393033663131366638393962663731353837393131353036613065623366 +36396164623861376235 diff --git a/ansible/roles/mosquitto/files/mosquitto.conf b/ansible/roles/mosquitto/files/mosquitto.conf new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/mosquitto/handlers/main.yml b/ansible/roles/mosquitto/handlers/main.yml new file mode 100644 index 0000000..4b109d6 --- /dev/null +++ b/ansible/roles/mosquitto/handlers/main.yml @@ -0,0 +1,25 @@ +--- + +- name: reload mosquitto + become: yes + service: + name: mosquitto + state: reloaded + +- name: restart mosquitto + become: yes + service: + name: mosquitto + state: restarted + +- name: start mosquitto + become: yes + service: + name: mosquitto + state: started + +- name: stop mosquitto + become: yes + service: + name: mosquitto + state: stopped \ No newline at end of file diff --git a/ansible/roles/mosquitto/tasks/main.yml b/ansible/roles/mosquitto/tasks/main.yml new file mode 100644 index 0000000..123910a --- /dev/null +++ b/ansible/roles/mosquitto/tasks/main.yml @@ -0,0 +1,19 @@ +- name: Install mosquitto + become: yes + ansible.builtin.package: + name: mosquitto + state: present + +- name: Copy configuration + become: yes + copy: + src: mosquitto.conf + dest: /etc/mosquitto/conf.d/mosquitto.conf + notify: + - restart mosquitto + +- name: Make sure mosquitto service is running + become: yes + ansible.builtin.systemd: + state: started + name: mosquitto \ No newline at end of file diff --git a/ansible/setup.yaml b/ansible/setup.yaml index cbf8744..e340eaa 100644 --- a/ansible/setup.yaml +++ b/ansible/setup.yaml @@ -4,4 +4,12 @@ roles: - common tags: - - common \ No newline at end of file + - common + +- name: Setup mosquitto + # gather_facts: no + hosts: mosquitto + roles: + - mosquitto + tags: + - mosquitto \ No newline at end of file