---
- name: "π Read the MCP token this controller already issued"
ansible.builtin.set_fact:
jenkins_mcp_token: "{{ lookup('mcp_credential', application_id) }}"
- name: "π Resolve {{ application_id }} hosting node + container id"
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}"
vars:
resolve_service_key: "{{ entity_name }}"
resolve_output_prefix: JENKINS
resolve_compose_cid: "{{ JENKINS_CONTAINER }}"
- name: "β³ Wait until the controller serves requests"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/ready.yml"
- name: "π©Ί Check the stored token against the running controller"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/probe.yml"
when: jenkins_mcp_token | length > 0
- name: "π Take over the API token the controller minted for MCP clients"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/provision.yml"
when: jenkins_mcp_token | length == 0 or jenkins_mcp_token_probe.rc | default(1) != 0
- name: "π©Ί Re-check the freshly read token"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/probe.yml"
when: jenkins_mcp_token_probe is not defined or jenkins_mcp_token_probe.rc != 0
- name: "π Refuse a controller whose MCP token every client would be rejected with"
ansible.builtin.assert:
that:
- jenkins_mcp_token_probe.rc == 0
fail_msg: >-
Jenkins rejected the API token stored for {{ application_id }}, so every MCP
client would be configured with a credential the controller answers 401 to.
- name: "π©Ί Verify the upstream plugin answers that credential"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/verify.yml"
- name: "π Hand the controller's API token to the adapter"
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-ai-mcp-adapter/tasks/upstream_key.yml') }}"
vars:
mcp_upstream_key_path: "{{ [JENKINS_MCP_INSTANCE_DIR, 'upstream.env'] | path_join }}"
mcp_upstream_key: "{{ (JENKINS_MCP_USERNAME ~ ':' ~ jenkins_mcp_token) | b64encode }}"
- name: "π§± Rebuild the MCP adapter of {{ application_id }} now the bearer exists"
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-ai-mcp-adapter/tasks/rebuild.yml') }}"
when: not mcp_upstream_written.changed
- name: "πΏ Flush compose handlers for {{ application_id }}"
ansible.builtin.meta: flush_handlers
- name: "β³ Wait until the recreated controller serves requests again"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/mcp/ready.yml"