Hi,
i’m a newbie in ansible. I work with the ansible playbook of spantaleev for the matrix docker ansible deploy and at the moment i finished some automations for updating or installing vms or container in my homelab with my own gitlab and Ansible Semaphore.
Yesterday i tried to integrate my matrix server, but i struggle with the correct way to do this.
Status:
At the moment i have the vm and on the vm is the playbook GitHub - spantaleev/matrix-docker-ansible-deploy: 🐳 Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
For example to update the matrix server i need to execute following commands:
- git pull
- just roles
- ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start
Now i want to migrate this steps in my semaphore and i tried to build some playbooks to execute this commands, but never it works.
First i tried to create a playbook to execute the commands on the remote host.
---
- name: Git-Pull, Rollen ausführen, und Setup mit Tags
hosts: matrix
become: yes
tasks:
- name: Git-Repository aktualisieren
git:
repo: 'https://github.com/spantaleev/matrix-docker-ansible-deploy'
dest: '/opt/matrix-docker-ansible-deploy'
update: yes
force: yes # Optional, erzwingt das Update, auch wenn es lokale Änderungen gibt
- name: Ansible-Rollen ausführen
command: 'just roles'
args:
chdir: '/opt/matrix-docker-ansible-deploy' # Das Verzeichnis, in dem der Befehl ausgeführt wird
- name: Ansible-Setup-Playbook mit Tags ausführen
command: 'ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start' # Playbook mit Tags ausführen
args:
chdir: '/opt/matrix-docker-ansible-deploy' # Das Verzeichnis, in dem der Befehl ausgeführt wird
but the commands failed with “just not found”
fatal: [matrix]: FAILED! => {"changed": false, "cmd": "ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start", "msg": "[Errno 2] Datei oder Verzeichnis nicht gefunden: b'ansible-playbook'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
i also tried with shell instead of command and env “shell path”. It also failed.
- name: Ansible-Rollen ausführen
shell: "/usr/bin/just roles"
args:
chdir: '/opt/matrix-docker-ansible-deploy'
environment:
SHELL: "/bin/bash" # Wechseln Sie zu bash, falls /bin/sh Probleme bereitet
PATH: "/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin" # PATH sicherstellen
so i tried another way. Chatgpt recommended me, i can pull the repo and push it in my gitlab to use it. I did solve the pull and push, and could automate this, but i dont know, how i can use it useful. i prefer an easier way.
Note: in the playbook for matrix i need to use a vars.yaml in Inventory:
Maybe anyone here can explain me, how i can solve this easier. I think i stuck in my minds.
Thanks