--- # The CLI owns its config file format, so the role drives `multica config set` # rather than templating config.json. Each key is read back first, so a # converged host reports zero changes. - name: Config | Build the desired configuration ansible.builtin.set_fact: _multica_desired_config: >- {{ { 'server_url': multica_server_url, 'app_url': multica_app_url, 'workspaces_root': multica_workspaces_root, 'device_name': multica_device_name, 'runtime_name': multica_runtime_name, 'max_concurrent_tasks': multica_max_concurrent_tasks, 'poll_interval': multica_poll_interval, 'heartbeat_interval': multica_heartbeat_interval, 'agent_timeout': multica_agent_timeout, 'disable_auto_update': ('true' if multica_disable_auto_update | bool else 'false'), } | dict2items | rejectattr('value', 'equalto', '') | list | items2dict }} - name: Config | Read the current configuration ansible.builtin.command: argv: "{{ _multica_cmd + ['config', 'show'] }}" become: true become_user: "{{ multica_user }}" environment: "{{ _multica_user_env }}" register: _multica_config_show changed_when: false check_mode: false # `config show` prints "key:value", with "(not set)" for unset keys. - name: Config | Parse it ansible.builtin.set_fact: _multica_current_config: >- {{ dict( _multica_config_show.stdout_lines | select('match', '^[a-z_]+:') | map('regex_replace', '^([a-z_]+):\s*(.*?)\s*$', '\1|\2') | map('split', '|') ) }} - name: Config | Apply the keys that differ ansible.builtin.command: argv: "{{ _multica_cmd + ['config', 'set', item.key, item.value] }}" become: true become_user: "{{ multica_user }}" environment: "{{ _multica_user_env }}" loop: "{{ _multica_desired_config | dict2items }}" loop_control: label: "{{ item.key }}={{ item.value }}" when: (_multica_current_config[item.key] | default('(not set)')) != item.value changed_when: true notify: restart multica daemon