--- - name: Загрузить декларативную конфигурацию доступа NetBird ansible.builtin.set_fact: netbird_access_cfg: "{{ lookup('file', role_path ~ '/files/access.yml') | from_yaml }}" - name: Положить скрипт синхронизации доступа NetBird ansible.builtin.copy: src: sync_access.py dest: "{{ netbird_dir }}/sync_access.py" owner: root group: root mode: "0700" - name: Записать конфигурацию доступа NetBird ansible.builtin.copy: dest: "{{ netbird_dir }}/access.json" content: "{{ netbird_access_cfg | to_json }}" owner: root group: root mode: "0600" - name: Подготовить базовое окружение для sync_access.py ansible.builtin.set_fact: netbird_access_env: NB_DOMAIN: "{{ netbird_domain }}" NB_API_TOKEN: "{{ netbird_effective_api_token }}" no_log: true - name: Добавить текущие клиентские setup-ключи в окружение sync_access.py ansible.builtin.set_fact: netbird_access_env: "{{ netbird_access_env | combine({item.secret: lookup('env', item.secret)}) }}" loop: "{{ netbird_access_cfg.setup_keys | default([]) }}" loop_control: label: "{{ item.name }}" no_log: true - name: Синхронизировать группы, Exit Nodes, DNS, ключи и пиры NetBird ansible.builtin.command: "python3 {{ netbird_dir }}/sync_access.py {{ netbird_dir }}/access.json" environment: "{{ netbird_access_env }}" register: netbird_access_raw changed_when: (netbird_access_raw.stdout | from_json).changed no_log: true - name: Разобрать результат синхронизации доступа NetBird ansible.builtin.set_fact: netbird_access_state: "{{ netbird_access_raw.stdout | from_json }}" netbird_access_summary: changed: "{{ (netbird_access_raw.stdout | from_json).changed }}" changes: "{{ (netbird_access_raw.stdout | from_json).changes }}" warnings: "{{ (netbird_access_raw.stdout | from_json).warnings }}" updated_secret_names: "{{ (netbird_access_raw.stdout | from_json).updated_secret_names }}" no_log: true - name: Сохранить клиентские setup-ключи NetBird в Infisical ansible.builtin.shell: | set -euo pipefail infisical secrets set \ --domain="${INFISICAL_DOMAIN}" \ --token="${INFISICAL_TOKEN}" \ --env=prod \ --projectId="${INFISICAL_PROJECT_ID}" \ --path="/services/netbird" \ "${NB_SECRET_KEY}=${NB_SECRET_VAL}" \ --silent args: executable: /bin/bash delegate_to: localhost become: false environment: NB_SECRET_KEY: "{{ item.key }}" NB_SECRET_VAL: "{{ item.value }}" loop: "{{ netbird_access_state.updated_secrets | default({}) | dict2items }}" loop_control: label: "{{ item.key }}" when: (netbird_access_state.updated_secrets | default({}) | length) > 0 changed_when: true no_log: true