Skip to content

Commit 26e0068

Browse files
committed
Experiment: Update integration test to include setup role
1 parent 8636bf3 commit 26e0068

File tree

8 files changed

+130
-34
lines changed

8 files changed

+130
-34
lines changed

tests/integration/mcpservers.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"github-server": {
3+
"type": "http",
4+
"url": "https://api.githubcopilot.com/mcp/",
5+
"description": "GitHub MCP Server - Access GitHub repositories, issues, and pull requests"
6+
},
7+
"aws-iam-mcp-server": {
8+
"type": "stdio",
9+
"command": "uvx",
10+
"args": ["awslabs.iam-mcp-server"],
11+
"description": "AWS IAM MCP Server - Manage AWS IAM resources through MCP protocol"
12+
}
13+
}
14+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: Setup integration test inventory
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
vars:
7+
# Default to the test target directory if not specified
8+
target_dir: "{{ ansible_mcp_target_dir | default(playbook_dir | dirname | dirname + '/targets') }}"
9+
integration_dir: "{{ playbook_dir | dirname | dirname }}"
10+
ansible_mcp_inventory_dir: "{{ ansible_mcp_inventory_dir | default(target_dir) }}"
11+
ansible_mcp_inventory_file: "{{ ansible_mcp_inventory_file | default(ansible_mcp_inventory_dir + '/inventory.yml') }}"
12+
# Default to shared mcpservers.json in integration directory, allow per-target override
13+
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path | default(integration_dir + '/mcpservers.json') }}"
14+
github_mcp_pat: "{{ github_mcp_pat | default('') }}"
15+
roles:
16+
- role: setup
17+
vars:
18+
ansible_mcp_inventory_dir: "{{ ansible_mcp_inventory_dir }}"
19+
ansible_mcp_inventory_file: "{{ ansible_mcp_inventory_file }}"
20+
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path }}"
21+
github_mcp_pat: "{{ github_mcp_pat }}"
22+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Ensure inventory directory exists
3+
ansible.builtin.file:
4+
path: "{{ ansible_mcp_inventory_dir | default(playbook_dir) }}"
5+
state: directory
6+
mode: '0755'
7+
8+
- name: Generate inventory file from template
9+
ansible.builtin.template:
10+
src: "{{ ansible_mcp_inventory_template | default('inventory.yml.j2') }}"
11+
dest: "{{ ansible_mcp_inventory_file | default(ansible_mcp_inventory_dir | default(playbook_dir) + '/inventory.yml') }}"
12+
mode: '0644'
13+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
all:
2+
children:
3+
mcp_servers:
4+
hosts:
5+
github_server:
6+
ansible_connection: ansible.mcp.mcp
7+
ansible_mcp_server_name: github-server
8+
ansible_mcp_server_args: []
9+
ansible_mcp_server_env:
10+
{% if github_mcp_pat is defined and github_mcp_pat | length > 0 %}
11+
GITHUB_PERSONAL_ACCESS_TOKEN: "{{ github_mcp_pat }}"
12+
{% else %}
13+
{}
14+
{% endif %}
15+
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path | default('/opt/mcp/mcpservers.json') }}"
16+
aws_iam_server:
17+
ansible_connection: ansible.mcp.mcp
18+
ansible_mcp_server_name: aws-iam-mcp-server
19+
ansible_mcp_server_args:
20+
- --readonly
21+
ansible_mcp_server_env:
22+
AWS_REGION: us-east-1
23+
AWS_PROFILE: default
24+
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path | default('/opt/mcp/mcpservers.json') }}"
25+

tests/integration/targets/server_info/generate_inventory.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/integration/targets/server_info/runme.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
#!/usr/bin/env bash
22
set -eux
33
export ANSIBLE_CALLBACKS_ENABLED=profile_tasks
4-
export ANSIBLE_ROLES_PATH=../
54

65
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7-
MANIFEST_PATH="${SCRIPT_DIR}/mcpservers.json"
6+
INTEGRATION_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
7+
# Use shared mcpservers.json from integration directory (can be overridden per-target if needed)
8+
MANIFEST_PATH="${INTEGRATION_DIR}/mcpservers.json"
89
INVENTORY="${SCRIPT_DIR}/inventory.yml"
10+
# Try to use the role's playbook first (for local testing), fall back to target's playbook (for ansible-test)
11+
ROLE_PLAYBOOK="${INTEGRATION_DIR}/roles/setup/setup_inventory.yml"
12+
TARGET_PLAYBOOK="${SCRIPT_DIR}/setup_tasks.yml"
13+
if [ -f "${ROLE_PLAYBOOK}" ]; then
14+
SETUP_PLAYBOOK="${ROLE_PLAYBOOK}"
15+
export ANSIBLE_ROLES_PATH="${INTEGRATION_DIR}/roles"
16+
else
17+
# Fallback for ansible-test (roles/ directory not copied)
18+
SETUP_PLAYBOOK="${TARGET_PLAYBOOK}"
19+
fi
920

1021
# Cleanup function to remove generated inventory file
1122
cleanup() {
@@ -17,16 +28,17 @@ cleanup() {
1728
# Set up trap early to ensure cleanup runs on error/early exit
1829
trap cleanup EXIT
1930

31+
# Get GitHub PAT from environment variables (github_mcp_pat should be set by zuul/ansible-test)
2032
GITHUB_PAT_VALUE="${github_mcp_pat:-${ANSIBLE_TEST_GITHUB_PAT:-${GITHUB_PAT:-${GITHUB_TOKEN:-${GITHUB_PERSONAL_ACCESS_TOKEN:-}}}}}"
2133

22-
# Generate inventory file with PAT injected from template
23-
# This will overwrite the existing inventory.yml file with the generated version
24-
GENERATE_INVENTORY="${SCRIPT_DIR}/generate_inventory.yml"
25-
if [ -n "${GITHUB_PAT_VALUE:-}" ]; then
26-
ansible-playbook -c local "${GENERATE_INVENTORY}" -e "github_mcp_pat=${GITHUB_PAT_VALUE}" -e "ansible_mcp_manifest_path=${MANIFEST_PATH}" "$@"
27-
else
28-
ansible-playbook -c local "${GENERATE_INVENTORY}" -e "ansible_mcp_manifest_path=${MANIFEST_PATH}" "$@"
29-
fi
34+
# Generate inventory file using setup playbook
35+
# Always pass github_mcp_pat (even if empty) so template can check if it's defined
36+
ansible-playbook -c local "${SETUP_PLAYBOOK}" \
37+
-e "github_mcp_pat=${GITHUB_PAT_VALUE:-}" \
38+
-e "ansible_mcp_manifest_path=${MANIFEST_PATH}" \
39+
-e "ansible_mcp_inventory_file=${INVENTORY}" \
40+
-e "ansible_mcp_inventory_dir=${SCRIPT_DIR}" \
41+
"$@"
3042

3143
# Run integration tests
3244
ansible-playbook -i "${INVENTORY}" "${SCRIPT_DIR}/tasks/main.yml" -e "ansible_mcp_manifest_path=${MANIFEST_PATH}" "$@"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# This playbook is based on roles/setup/
3+
# It exists in the target directory for ansible-test compatibility
4+
# The canonical source is roles/setup/tasks/main.yml - update tasks when the role changes
5+
- name: Setup integration test inventory
6+
hosts: localhost
7+
connection: local
8+
gather_facts: false
9+
vars:
10+
# Default to the test target directory if not specified
11+
target_dir: "{{ ansible_mcp_target_dir | default(playbook_dir) }}"
12+
integration_dir: "{{ playbook_dir | dirname | dirname }}"
13+
ansible_mcp_inventory_dir: "{{ ansible_mcp_inventory_dir | default(target_dir) }}"
14+
ansible_mcp_inventory_file: "{{ ansible_mcp_inventory_file | default(ansible_mcp_inventory_dir + '/inventory.yml') }}"
15+
# Default to shared mcpservers.json in integration directory, allow per-target override
16+
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path | default(integration_dir + '/mcpservers.json') }}"
17+
github_mcp_pat: "{{ github_mcp_pat | default('') }}"
18+
tasks:
19+
# Tasks from roles/setup/tasks/main.yml (inlined for ansible-test compatibility)
20+
- name: Ensure inventory directory exists
21+
ansible.builtin.file:
22+
path: "{{ ansible_mcp_inventory_dir }}"
23+
state: directory
24+
mode: '0755'
25+
26+
- name: Generate inventory file from template
27+
ansible.builtin.template:
28+
src: "{{ ansible_mcp_inventory_template | default('inventory.yml.j2') }}"
29+
dest: "{{ ansible_mcp_inventory_file }}"
30+
mode: '0644'
31+

tests/integration/targets/server_info/tasks/main.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
gather_facts: false
55
vars:
66
ansible_mcp_manifest_path: "{{ ansible_mcp_manifest_path | default(playbook_dir | dirname + '/mcpservers.json') }}"
7+
github_pat: "{{ github_mcp_pat | default(lookup('env', 'GITHUB_PERSONAL_ACCESS_TOKEN'), true) }}"
78
tasks:
89
- name: Retrieve server info from GitHub MCP server
910
ansible.mcp.server_info:
1011
register: github_server_info
11-
when: >
12-
ansible_mcp_server_env is defined and
13-
ansible_mcp_server_env.GITHUB_PERSONAL_ACCESS_TOKEN is defined and
14-
ansible_mcp_server_env.GITHUB_PERSONAL_ACCESS_TOKEN | length > 0
12+
when: github_pat | length > 0
1513

1614
- name: Verify GitHub server_info result succeeded
1715
ansible.builtin.assert:
@@ -22,10 +20,7 @@
2220
- github_server_info.server_info.serverInfo.name is defined
2321
- github_server_info.server_info.serverInfo.version is defined
2422
fail_msg: "GitHub server_info does not contain expected structure"
25-
when: >
26-
ansible_mcp_server_env is defined and
27-
ansible_mcp_server_env.GITHUB_PERSONAL_ACCESS_TOKEN is defined and
28-
ansible_mcp_server_env.GITHUB_PERSONAL_ACCESS_TOKEN | length > 0
23+
when: github_pat | length > 0
2924

3025
- name: Test server_info with AWS IAM MCP server
3126
hosts: aws_iam_server

0 commit comments

Comments
 (0)