spantaleev / matrix-docker-ansible-deploy

🐳 Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
GNU Affero General Public License v3.0
4.9k stars 1.04k forks source link

Support for Ansible 4 #1066

Open theCalcaholic opened 3 years ago

theCalcaholic commented 3 years ago

Description

When using the playbook with Ansible 4, there are some yaml parsing errors, e.g.:

TASK [matrix-bridge-mautrix-signal : Ensure mautrix-signal config.yaml installed] *******************************************************************************************************************
task path: /home/<redacted>/private/projects/matrix-docker-ansible-deploy/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml:50
fatal: [HOST_URL REDACTED]: FAILED! => 
  msg: |-
    An unhandled exception occurred while templating '{{ matrix_mautrix_signal_configuration_yaml|from_yaml|combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ matrix_mautrix_signal_configuration_extension_yaml|from_yaml if matrix_mautrix_signal_configuration_extension_yaml|from_yaml is mapping else {} }}'. Error was a <class 'yaml.parser.ParserError'>, original message: while parsing a block mapping
      in "<unicode string>", line 1, column 1:
        bridge:
        ^
    expected <block end>, but found '<block mapping start>'
      in "<unicode string>", line 9, column 3:
          double_puppet_allow_discovery: true

How to reproduce

  1. Configure any mautrix bridge in your host vars
  2. Make sure, to specify something in matrix_mautrix_signal_configuration_extension_yaml
  3. Try to deploy using ansible 4

Workaround/Fix

These errors can be worked around by downgrading ansible (tested with 2.10, since that's been used in my working setup on another machine) or by setting the matrix_mautrix_*configuration variables in multiple steps, e.g.:

- set_fact:
    part_1: "{{ matrix_mautrix_signal_configuration_yaml|from_yaml }}"
- set_fact:
    part_2: "{{ matrix_mautrix_signal_configuration_extension_yaml|from_yaml }}"

- set_fact:
    matrix_mautrix_signal_configuration: "{{ part_1|combine(part_2, recursive=True) }}"

For the sake of completeness, here is the relevant section in the defaults/main.yml of matrix-bridge-mautrix-signal:

matrix_mautrix_signal_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}"

matrix_mautrix_signal_configuration_extension_yaml: |
  # Your custom YAML configuration goes here.
  # This configuration extends the default starting configuration (`matrix_mautrix_signal_configuration_yaml`).
  #
  # You can override individual variables from the default configuration, or introduce new ones.
  #
  # If you need something more special, you can take full control by
  # completely redefining `matrix_mautrix_signal_configuration_yaml`.

matrix_mautrix_signal_configuration_extension: "{{ matrix_mautrix_signal_configuration_extension_yaml|from_yaml if matrix_mautrix_signal_configuration_extension_yaml|from_yaml is mapping else {} }}"

# Holds the final configuration (a combination of the default and its extension).
# You most likely don't need to touch this variable. Instead, see `matrix_mautrix_signal_configuration_yaml`.
matrix_mautrix_signal_configuration: "{{ matrix_mautrix_signal_configuration_yaml|from_yaml|combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}"
spantaleev commented 3 years ago

I'm not using mx-puppet-signal, but it seems like the matrix-synapse role does the same.

I have some custom stuff in matrix_synapse_configuration_extension_yaml and it all seems to be working. I can't reproduce this issue.


ansible --version:

ansible [core 2.11.0] 
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.5 (default, May 12 2021, 17:14:51) [GCC 10.2.0]
  jinja version = 3.0.1
  libyaml = True

This is on Archlinux with ansible = 4.0.0-1 and ansible-core = 2.11.0-4.

Perhaps you're on some other version of something or some other dependency is causing trouble.

theCalcaholic commented 3 years ago

I was using mautrix-signal not mx-puppet-signal. Anyways, I'll see if I can provide a minimal setup for the issue (otherwise, I'll close the issue).

My installed packages are:

$ pip freeze
ansible==4.0.0
ansible-core==2.11.0
cffi==1.14.5
cryptography==3.4.7
Jinja2==3.0.1
MarkupSafe==2.0.1
packaging==20.9
pycparser==2.20
pyparsing==2.4.7
PyYAML==5.4.1
resolvelib==0.5.4

(which is what I got as of yesterday from pip install ansible)

seanfarley commented 3 years ago

I also ran into this error separately (just core matrix, no bridges) with the import-postgres tag (downgrading ansible allowed things to chug along).