Best way to update this service (Matrix Ansible)

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

just is a prerequisite, you will need to install it before you can use it.

its installed on both (ansible semaphore server and matrix server)
On the Matrix Server i used it before locally

i wrote it at the beginning:
brave_UPowY4LXx3

What does this return:

ls -lah /usr/bin/just

And:

which just

in the ansible semaphore container i cant use this commands.

on matrix
root@matrix:~# ls -lah /usr/bin/just
-rwxr-xr-x 1 root root 3.5M Mar 12 05:47 /usr/bin/just
root@matrix:~# which just
/usr/bin/just
root@matrix:~#

It’s odd that using the CLI you have just but Ansible doesn’t see it, perhaps add a check for it before trying to run it?

    - name: Check just
      ansible.builtin.stat:
        path: /usr/bin/just
      register: just_path 

    - name: Just is required
      ansible.builtin.assert:
        that:
           - just_path.stat.exists | bool
        fail_msg: "The check for /usr/bin/just failed."

    - name: Ansible-Rollen ausführen
      command: 'just roles'
      args:
        chdir: '/opt/matrix-docker-ansible-deploy'  # Das Verzeichnis, in dem der Befehl ausgeführt wird

if i can completely use another way i would prefer it.

Today morning i test a new playbook for direct using the github playbook and use just in the container of ansible semaphore.

i came a good way forward.
I add the vars.yml of my old playbook into the inventory of my new ansible installation. After i added “just” to my requirements and its installed.

At the moment i get this error:

1:38:51 PM
Task 287 added to queue
1:38:53 PM
Started: 287
1:38:53 PM
Run TaskRunner with template: Matrix - Update Playbook
1:38:54 PM
Preparing: 287
1:38:54 PM
Updating Repository https://github.com/spantaleev/matrix-docker-ansible-deploy
1:38:55 PM
ERROR! the role 'galaxy/playbook_help' was not found in /tmp/semaphore/repository_3_15/roles:/tmp/semaphore/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/tmp/semaphore/repository_3_15
1:38:55 PM
      ^ here
1:38:55 PM
    - role: galaxy/playbook_help
1:38:55 PM
    # Most of the roles below are not distributed with the playbook, but downloaded separately using `ansible-galaxy` via the `just roles` command (see `justfile`).
1:38:55 PM
1:38:55 PM
The offending line appears to be:
1:38:55 PM
1:38:55 PM
be elsewhere in the file depending on the exact syntax problem.
1:38:55 PM
The error appears to be in '/tmp/semaphore/repository_3_15/setup.yml': line 8, column 7, but may
1:38:55 PM
1:38:55 PM
No roles/requirements.yml file found. Skip galaxy install process.
1:38:55 PM
collections/requirements.yml has no changes. Skip galaxy install process.
1:38:55 PM
installing static inventory
1:38:55 PM
Already up to date.
1:38:55 PM
 * branch              master     -> FETCH_HEAD
1:38:55 PM
From https://github.com/spantaleev/matrix-docker-ansible-deploy
1:38:56 PM
Running playbook failed: exit status 1
ERROR! the role 'galaxy/playbook_help' was not found in /tmp/semaphore/repository_3_15/roles:/tmp/semaphore/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/tmp/semaphore/repository_3_15

iam not sure, how i have to add the role.

in my old local installation “galaxy” is in “roles” in the repository.
“/opt/matrix-docker-ansible-deploy/roles/galaxy”

in my ols installation i simply used “just roles”. I am not sure what i have to do in ansible semaphore to add the roles.

Thanks

The path for roles installed using ansible-galaxy can be set in a ansible.cfg file, for example:

[defaults]
roles_path = roles/galaxy

its not my repository. in this case i clone directly from GitHub - spantaleev/matrix-docker-ansible-deploy: 🐳 Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker.

But in the ansible.cfg the path not exist.

[defaults]
retry_files_enabled = False
stdout_callback = yaml

[connection]
pipelining = True