diff --git a/functional-test/src/test/groovy/functional/YamlParsingSpec.groovy b/functional-test/src/test/groovy/functional/YamlParsingSpec.groovy new file mode 100644 index 0000000..fb301e1 --- /dev/null +++ b/functional-test/src/test/groovy/functional/YamlParsingSpec.groovy @@ -0,0 +1,34 @@ +package functional + +import functional.base.BaseTestConfiguration +import org.testcontainers.spock.Testcontainers + +@Testcontainers +class YamlParsingSpec extends BaseTestConfiguration { + + static String PROJ_NAME = 'ansible-yaml-parsing' + static String NODE_1 = 'server1' + static String NODE_2 = 'server2' + + def setupSpec() { + startCompose() + configureRundeck(PROJ_NAME, 'server1') + } + + void "hide warnings"() { + when: + def result = client.apiCall {api-> api.listNodes(PROJ_NAME,'.*')} + + then: + result != null + result.size() == 3 + result.get(NODE_1) != null + result.get(NODE_1).getAttributes().get("ansible_host") == "192.168.1.10" + result.get(NODE_1).getAttributes().get("ansible_user") == "user2" + result.get(NODE_1).getAttributes().get("http_port") == "8080" + result.get(NODE_2) != null + result.get(NODE_2).getAttributes().get("ansible_host") == "192.168.1.20" + result.get(NODE_2).getAttributes().get("ansible_user") == "user3" + result.get(NODE_2).getAttributes().get("http_port") == "8080" + } +} diff --git a/functional-test/src/test/resources/docker/ansible-yaml-parsing/ansible.cfg b/functional-test/src/test/resources/docker/ansible-yaml-parsing/ansible.cfg new file mode 100644 index 0000000..e57197a --- /dev/null +++ b/functional-test/src/test/resources/docker/ansible-yaml-parsing/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +inventory=/home/rundeck/ansible-yaml-parsing/inventory_duplicate_key.yaml +interpreter_python=/usr/bin/python3 + + + diff --git a/functional-test/src/test/resources/docker/ansible-yaml-parsing/inventory_duplicate_key.yaml b/functional-test/src/test/resources/docker/ansible-yaml-parsing/inventory_duplicate_key.yaml new file mode 100644 index 0000000..4d19fc7 --- /dev/null +++ b/functional-test/src/test/resources/docker/ansible-yaml-parsing/inventory_duplicate_key.yaml @@ -0,0 +1,16 @@ +all: + hosts: + server1: + ansible_host: 192.168.1.10 + ansible_user: user1 + # Duplicate key! + ansible_user: user2 # This will cause the warning + + server2: + ansible_host: 192.168.1.20 + ansible_user: user3 + + vars: + http_port: 80 + # Another duplicate key! + http_port: 8080 # This will also cause the warning diff --git a/functional-test/src/test/resources/docker/docker-compose.yml b/functional-test/src/test/resources/docker/docker-compose.yml index 9733514..f35d720 100644 --- a/functional-test/src/test/resources/docker/docker-compose.yml +++ b/functional-test/src/test/resources/docker/docker-compose.yml @@ -30,10 +30,11 @@ services: networks: - rundeck ports: - - "4440" + - "4440:4440" volumes: - ./ansible:/home/rundeck/ansible:rw - ./ansible-list:/home/rundeck/ansible-list:rw + - ./ansible-yaml-parsing:/home/rundeck/ansible-yaml-parsing:rw volumes: rundeck-data: diff --git a/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/acls/node-acl.aclpolicy b/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/acls/node-acl.aclpolicy new file mode 100644 index 0000000..596f7af --- /dev/null +++ b/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/acls/node-acl.aclpolicy @@ -0,0 +1,8 @@ +by: + urn: project:ansible-yaml-parsing +for: + storage: + - match: + path: 'keys/.*' + allow: [read] +description: Allow access to key storage \ No newline at end of file diff --git a/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/etc/project.properties b/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/etc/project.properties new file mode 100644 index 0000000..e18c109 --- /dev/null +++ b/functional-test/src/test/resources/project-import/ansible-yaml-parsing/rundeck-yaml-parsing/files/etc/project.properties @@ -0,0 +1,31 @@ +#edit below +project.disable.executions=false +project.disable.schedule=false +project.execution.history.cleanup.batch=500 +project.execution.history.cleanup.enabled=false +project.execution.history.cleanup.retention.days=60 +project.execution.history.cleanup.retention.minimum=50 +project.execution.history.cleanup.schedule=0 0 0 1/1 * ? * +project.jobs.gui.groupExpandLevel=1 +project.later.executions.disable.value=0 +project.later.executions.disable=false +project.later.executions.enable.value= +project.later.executions.enable=false +project.later.schedule.disable.value= +project.later.schedule.disable=false +project.later.schedule.enable.value= +project.later.schedule.enable=false +project.name=ansible-yaml-parsing +project.nodeCache.enabled=false +project.nodeCache.firstLoadSynch=true +project.output.allowUnsanitized=false +project.retry-counter=3 +project.ssh-authentication=privateKey +resources.source.1.type=local +resources.source.2.config.ansible-config-file-path=/home/rundeck/ansible-yaml-parsing/ansible.cfg +resources.source.2.config.ansible-gather-facts=false +resources.source.2.config.ansible-ignore-errors=true +resources.source.2.config.ansible-inventory=/home/rundeck/ansible-yaml-parsing/inventory_duplicate_key.yaml +resources.source.2.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory +service.FileCopier.default.provider=sshj-scp +service.NodeExecutor.default.provider=sshj-ssh \ No newline at end of file diff --git a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java index 718334b..1499c5d 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java @@ -63,6 +63,15 @@ public String getNodeList() throws IOException, AnsibleException { processAnsibleVault(stdinVariables, procArgs); processLimit(procArgs); + procArgs.add("2>/dev/null"); + + String allCmd = String.join(" ", procArgs); + + procArgs.clear(); + procArgs.add("bash"); + procArgs.add("-c"); + procArgs.add(allCmd); + if(debug){ System.out.println("getNodeList " + procArgs); }