From f8067a11520f80b96325fb5f54885e607ad81d39 Mon Sep 17 00:00:00 2001 From: Nuno Ferreira Date: Mon, 24 Aug 2020 18:07:22 +0100 Subject: [PATCH] added ability to import ansible_port if set on the inventory file --- .../plugins/AnsibleResourceModelSource.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/batix/rundeck/plugins/AnsibleResourceModelSource.java b/src/main/java/com/batix/rundeck/plugins/AnsibleResourceModelSource.java index 09052964..a8c62e6e 100644 --- a/src/main/java/com/batix/rundeck/plugins/AnsibleResourceModelSource.java +++ b/src/main/java/com/batix/rundeck/plugins/AnsibleResourceModelSource.java @@ -293,9 +293,21 @@ public INodeSet getNodes() throws ResourceModelSourceException { System.out.println("[warn] Problem getting the ansible_host attribute from node " + hostname); } + String port = root.get("inventory_hostname").getAsString(); + try { + if (root.has("ansible_port")) { + port = root.get("ansible_port").getAsString(); + } else { // fallback to default ssh port + port = "22"; + } + }catch(Exception ex){ + System.out.println("[warn] Problem getting the ansible_port attribute from node " + port); + } + String nodename = root.get("inventory_hostname").getAsString(); + String hostname_with_port = hostname + ":" + port; - node.setHostname(hostname); + node.setHostname(hostname_with_port); node.setNodename(nodename); String username = System.getProperty("user.name"); // TODO better default?