-
Notifications
You must be signed in to change notification settings - Fork 98
RUN-4085 Generate Inventory with SSH password authentication #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
7bd89d5
add new feature to add the node auth in the generated inventory
ltamaster de654c6
fix getting ssh-password from nodes
ltamaster 1fa16df
group_vars and properties in nodeexecutor
edbaltra 71b4af9
Added Inline Playbook option for testing
edbaltra 70d64d2
authentitacion debug logs
edbaltra 1f7a793
fix encrypted group vars for generated inventory
ltamaster 4a4c3c2
Added checkboxes at project level, added execution-tmp folder creatio…
edbaltra 1590942
Added Vault validation and Name escaping, added debug logs to yaml fi…
edbaltra e635344
clean debug messages
ltamaster d6635a3
removed ANSIBLE_GENERATE_INVENTORY_NODES_AUTH to only use plugin grou…
edbaltra 0b6c7dd
reverted back to node exec and project config file
edbaltra 736f0d6
remove flag generate inventory at workflow step level
ltamaster 5ab9954
clean messages
ltamaster 0a77dab
fix debug message
ltamaster 9fe662a
Added unit tests
edbaltra 22d8b74
fix issue with password with especial character
ltamaster d6fd35a
Added unit tests for passwords with special characters
edbaltra 3298d3b
clean AnsiblePlaybookInlineWorkflowNodeStep
ltamaster b514ed2
Added Multiple node auth functional tests, added missing README files
edbaltra 24d84cc
remove unnecesary logs
edbaltra 35ffd42
improve workflow step node authentication type
ltamaster 80a3296
Refactored code, added private key and functoinal test
edbaltra 84d816a
changed error messages, changed debug logs
edbaltra 684aa51
added node name sanitization and unit test
edbaltra 6a46aed
send private keys to runner
ltamaster 85a4136
addressed copilot comments
edbaltra 6d8c548
Copilot comments
edbaltra 65ab770
enable again the send node keys to runner in node-executor
ltamaster f224449
copilot comments
edbaltra 19ad662
copilot comments
edbaltra 636cede
copilot comments
edbaltra 69f0b9d
Copilot comments
edbaltra f40645c
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 46e56db
Update functional-test/build.gradle
edbaltra 27b2e6b
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 958f407
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 19045a8
copilot comments
edbaltra 93a0f74
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 01e918f
Update functional-test/src/test/resources/project-import/ansible-mult…
edbaltra bc32a3b
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 6b4e921
Update src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRun…
edbaltra 2784ac9
Copilot comments
edbaltra a435600
Copilot comments debug
edbaltra 6bf39e9
Update functional-test/src/test/resources/docker/ansible-multi-node-a…
edbaltra 65ae444
Final Copilot comments
edbaltra 7db271f
fix NPE
ltamaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| # Functional Tests for Ansible Plugin | ||
|
|
||
| This directory contains functional tests for the Rundeck Ansible plugin using Testcontainers and Docker. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Docker (Docker Desktop or Rancher Desktop) | ||
| - Java 11 or later | ||
| - Gradle 7.2 or later | ||
|
|
||
| ## Docker Configuration | ||
|
|
||
| The functional tests use Testcontainers to spin up Docker containers for Rundeck and SSH nodes. Depending on your Docker setup, you may need to configure the Docker socket path. | ||
|
|
||
| ### Option 1: Using ~/.testcontainers.properties (Recommended) | ||
|
|
||
| Create a file at `~/.testcontainers.properties` with the following content: | ||
|
|
||
| **For Rancher Desktop on macOS:** | ||
| ```properties | ||
| docker.host=unix:///Users/<your-username>/.rd/docker.sock | ||
| ``` | ||
|
|
||
| **For Docker Desktop on macOS/Linux:** | ||
| ```properties | ||
| docker.host=unix:///var/run/docker.sock | ||
| ``` | ||
|
|
||
| **For Windows with Docker Desktop:** | ||
| ```properties | ||
| docker.host=tcp://localhost:2375 | ||
| ``` | ||
|
|
||
| ### Option 2: Modify build.gradle | ||
|
|
||
| Edit `functional-test/build.gradle` and update the `docker.host` paths on lines 52-53: | ||
|
|
||
| ```gradle | ||
| systemProperty('docker.host', "unix:///path/to/your/docker.sock") | ||
| environment 'DOCKER_HOST', 'unix:///path/to/your/docker.sock' | ||
| ``` | ||
|
|
||
| ## Running the Tests | ||
|
|
||
| ### Run All Functional Tests | ||
|
|
||
| ```bash | ||
| ./gradlew :functional-test:functionalTest | ||
| ``` | ||
|
|
||
| ### Run Specific Test Suite | ||
|
|
||
| ```bash | ||
| # Multi-node authentication tests | ||
| ./gradlew :functional-test:functionalTest --tests "*MultiNodeAuthSpec*" | ||
|
|
||
| # Basic integration tests | ||
| ./gradlew :functional-test:functionalTest --tests "*BasicIntegrationSpec*" | ||
|
|
||
| # Plugin group tests | ||
| ./gradlew :functional-test:functionalTest --tests "*PluginGroupIntegrationSpec*" | ||
| ``` | ||
|
|
||
| ## Test Suites | ||
|
|
||
| ### MultiNodeAuthSpec | ||
| Tests the multi-node authentication feature where each node can have its own password stored in Rundeck's key storage. | ||
|
|
||
| **Tests:** | ||
| - `test ansible playbook with multi-node authentication` - Verifies Ansible playbooks execute across multiple nodes with per-node credentials | ||
| - `test multi-node authentication with different passwords` - Tests script execution on multiple nodes with different passwords | ||
| - `test nodes are accessible with different credentials` - Validates node registration and discovery | ||
| - `test passwords with special characters are properly escaped` - Verifies YAML escaping for special characters in passwords | ||
|
|
||
| **Test Environment:** | ||
| - 3 SSH nodes (ssh-node, ssh-node-2, ssh-node-3) | ||
| - Each node has a different password, including special characters | ||
| - Tests both WorkflowStep (Ansible playbooks) and NodeStep (scripts) execution | ||
|
|
||
| ### BasicIntegrationSpec | ||
| Basic integration tests for the Ansible plugin functionality. | ||
|
|
||
| ### PluginGroupIntegrationSpec | ||
| Tests for plugin group configuration and execution. | ||
|
|
||
| ## Test Structure | ||
|
|
||
| ``` | ||
| functional-test/ | ||
| ├── build.gradle # Test configuration | ||
| ├── README.md # This file | ||
| └── src/ | ||
| └── test/ | ||
| ├── groovy/functional/ # Test specifications | ||
| │ ├── MultiNodeAuthSpec.groovy | ||
| │ ├── BasicIntegrationSpec.groovy | ||
| │ └── PluginGroupIntegrationSpec.groovy | ||
| └── resources/ | ||
| ├── docker/ # Docker compose and configs | ||
| │ ├── docker-compose.yml | ||
| │ ├── ansible-multi-node-auth/ # Multi-node test configs | ||
| │ ├── keys/ # SSH keys for tests | ||
| │ ├── node/ # SSH node Docker configs | ||
| │ └── rundeck/ # Rundeck Docker configs | ||
| └── project-import/ # Rundeck project definitions | ||
| └── ansible-multi-node-auth/ | ||
| └── rundeck-ansible-multi-node-auth/ | ||
| ├── files/etc/project.properties | ||
| └── jobs/*.xml | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Tests Fail with "Could not find Docker socket" | ||
|
|
||
| **Problem:** Testcontainers cannot locate the Docker socket. | ||
|
|
||
| **Solution:** | ||
| 1. Verify Docker is running: `docker ps` | ||
| 2. Check your Docker socket path: | ||
| - Rancher Desktop: `ls -la ~/.rd/docker.sock` | ||
| - Docker Desktop: `ls -la /var/run/docker.sock` | ||
| 3. Update `~/.testcontainers.properties` or `build.gradle` with the correct path | ||
|
|
||
| ### Tests Timeout or Hang | ||
|
|
||
| **Problem:** Tests take too long or appear to hang. | ||
|
|
||
| **Solution:** | ||
| 1. Check Docker container status: `docker ps -a` | ||
| 2. Check Docker logs: `docker logs <container-id>` | ||
| 3. Increase test timeout in build.gradle if needed | ||
| 4. Ensure sufficient Docker resources (memory/CPU) | ||
|
|
||
| ### Port Conflicts | ||
|
|
||
| **Problem:** Tests fail with "port already in use" errors. | ||
|
|
||
| **Solution:** | ||
| 1. Check for running containers: `docker ps` | ||
| 2. Stop conflicting containers: `docker stop <container-name>` | ||
| 3. Clean up: `docker-compose down` in the docker directory | ||
|
|
||
| ### Platform Mismatch Warnings (Apple Silicon) | ||
|
|
||
| **Problem:** Warnings about platform mismatch (linux/amd64 vs linux/arm64). | ||
|
|
||
| **Solution:** These warnings are expected on Apple Silicon Macs and can be safely ignored. Docker will use Rosetta 2 for emulation. | ||
|
|
||
| ## Test Reports | ||
|
|
||
| After running tests, view the HTML report at: | ||
| ``` | ||
| functional-test/build/reports/tests/functionalTest/index.html | ||
| ``` | ||
|
|
||
| ## Adding New Tests | ||
|
|
||
| 1. Create a new Spock specification in `src/test/groovy/functional/` | ||
| 2. Extend `BaseTestConfiguration` for common test utilities | ||
| 3. Add any required Docker configs to `src/test/resources/docker/` | ||
| 4. Add project imports to `src/test/resources/project-import/` | ||
| 5. Follow existing test patterns for consistency | ||
|
|
||
| ## Multi-Node Authentication Feature | ||
|
|
||
| The multi-node authentication feature allows running Ansible playbooks across multiple nodes where each node has its own password stored in Rundeck's key storage. | ||
|
|
||
| **How it works:** | ||
| 1. Enable at project level: `project.ansible-generate-inventory-nodes-auth=true` | ||
| 2. Store per-node passwords in Key Storage with paths specified in node attributes | ||
| 3. Plugin generates `group_vars/all.yaml` with vault-encrypted passwords | ||
| 4. Ansible uses host-specific credentials from group_vars | ||
|
|
||
| **Requirements:** | ||
| - Must use Ansible Playbook **Workflow Steps** (not Node Steps); the multi-node authentication logic and inventory generation are only implemented for the Workflow Step variant of the plugin and are not executed for Node Steps, so enabling `project.ansible-generate-inventory-nodes-auth` while using Node Steps will not apply per-node credentials. This limitation exists because Node Steps run independently on each target node and do not share the global inventory context that the multi-node authentication feature relies on. | ||
| - Node attributes must include `ansible-ssh-password-storage-path` for each node | ||
| - Passwords are automatically encrypted using Ansible Vault | ||
| - Supports special characters with proper YAML escaping | ||
|
|
||
| See `MultiNodeAuthSpec.groovy` for comprehensive test examples. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.