Skip to content

Commit

Permalink
Merge pull request #383 from rundeck-plugins/optional-inventory-file-…
Browse files Browse the repository at this point in the history
…inventorylist

Error using new ansible inventory list with empty inventory (defined in ansible.cfg)
  • Loading branch information
ltamaster authored Jul 15, 2024
2 parents d3c74f9 + 6c315e2 commit 188ad91
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import functional.base.BaseTestConfiguration
import org.testcontainers.spock.Testcontainers

@Testcontainers
class LargeInventorySpec extends BaseTestConfiguration {
class InventoryListSpec extends BaseTestConfiguration {

static String PROJ_NAME = 'ansible-large-inventory'

Expand All @@ -16,11 +16,11 @@ class LargeInventorySpec extends BaseTestConfiguration {
def "test large inventory"(){
when:

def result = client.apiCall {api-> api.listNodes(PROJ_NAME,".*")}
def result = client.apiCall {api-> api.listNodes(PROJ_NAME,"tags:test")}

then:
result!=null
result.size()==8001
result.size()==8000
result.get("Node-0")!=null
result.get("Node-0").getAttributes().get("ansible_host") == "ssh-node"
result.get("Node-0").getAttributes().get("ansible_ssh_user") == "rundeck"
Expand All @@ -30,4 +30,18 @@ class LargeInventorySpec extends BaseTestConfiguration {
result.get("Node-7999").getAttributes().get("ansible_ssh_user") == "rundeck"
result.get("Node-7999").getAttributes().get("some-var") == "1234"
}

def "test empty inventory path"(){
when:

def result = client.apiCall {api-> api.listNodes(PROJ_NAME,"tags:fake")}

then:
result!=null
result.size()==35
result.get("node1")!=null
result.get("node1").getAttributes().get("ansible_host") == "node1"
result.get("node1").getAttributes().get("ansible_user") == "agent"
result.get("node1").getAttributes().get("ansible_port") == "22"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[defaults]
inventory = /home/rundeck/ansible-list/hosts
interpreter_python=/usr/bin/python3



37 changes: 37 additions & 0 deletions functional-test/src/test/resources/docker/ansible-list/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

[fake]
node1 ansible_host=node1 ansible_port=22 ansible_user=agent
node2 ansible_host=node2 ansible_port=22 ansible_user=agent
node3 ansible_host=node3 ansible_port=22 ansible_user=agent
node4 ansible_host=node4 ansible_port=22 ansible_user=agent
node5 ansible_host=node5 ansible_port=22 ansible_user=agent
node6 ansible_host=node6 ansible_port=22 ansible_user=agent
node7 ansible_host=node7 ansible_port=22 ansible_user=agent
node8 ansible_host=node8 ansible_port=22 ansible_user=agent
node9 ansible_host=node9 ansible_port=22 ansible_user=agent
node10 ansible_host=node10 ansible_port=22 ansible_user=agent
node11 ansible_host=node11 ansible_port=22 ansible_user=agent
node12 ansible_host=node12 ansible_port=22 ansible_user=agent
node13 ansible_host=node13 ansible_port=22 ansible_user=agent
node14 ansible_host=node14 ansible_port=22 ansible_user=agent
node15 ansible_host=node15 ansible_port=22 ansible_user=agent
node16 ansible_host=node16 ansible_port=22 ansible_user=agent
node17 ansible_host=node17 ansible_port=22 ansible_user=agent
node18 ansible_host=node18 ansible_port=22 ansible_user=agent
node19 ansible_host=node19 ansible_port=22 ansible_user=agent
node20 ansible_host=node20 ansible_port=22 ansible_user=agent
node21 ansible_host=node21 ansible_port=22 ansible_user=agent
node22 ansible_host=node22 ansible_port=22 ansible_user=agent
node23 ansible_host=node23 ansible_port=22 ansible_user=agent
node24 ansible_host=node24 ansible_port=22 ansible_user=agent
node25 ansible_host=node25 ansible_port=22 ansible_user=agent
node26 ansible_host=node26 ansible_port=22 ansible_user=agent
node27 ansible_host=node27 ansible_port=22 ansible_user=agent
node28 ansible_host=node28 ansible_port=22 ansible_user=agent
node29 ansible_host=node29 ansible_port=22 ansible_user=agent
node30 ansible_host=node30 ansible_port=22 ansible_user=agent
node31 ansible_host=node31 ansible_port=22 ansible_user=agent
node32 ansible_host=node32 ansible_port=22 ansible_user=agent
node33 ansible_host=node33 ansible_port=22 ansible_user=agent
node34 ansible_host=node34 ansible_port=22 ansible_user=agent
node35 ansible_host=node35 ansible_port=22 ansible_user=agent
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
- "4440"
volumes:
- ./ansible:/home/rundeck/ansible:rw
- ./ansible/ansible.cfg:/etc/ansible/ansible.cfg:rw
- ./ansible-list:/home/rundeck/ansible-list:rw

volumes:
rundeck-data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ 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/large-inventory.py
resources.source.2.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
resources.source.3.config.ansible-config-file-path=/home/rundeck/ansible-list
resources.source.3.config.ansible-gather-facts=false
resources.source.3.config.ansible-ignore-errors=true
resources.source.3.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
service.FileCopier.default.provider=sshj-scp
service.NodeExecutor.default.provider=sshj-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public String getNodeList() throws IOException, AnsibleException {

List<String> procArgs = new ArrayList<>();
procArgs.add(ANSIBLE_INVENTORY);
procArgs.add("--inventory-file" + "=" + inventory);
//inventory can be defined in ansible.cfg
if(inventory!=null && !inventory.isEmpty()){
procArgs.add("--inventory-file" + "=" + inventory);
}
procArgs.add("--list");
procArgs.add("-y");

Expand Down

0 comments on commit 188ad91

Please sign in to comment.