diff --git a/src/main/groovy/com/rundeck/plugins/ansible/ansible/InventoryList.java b/src/main/groovy/com/rundeck/plugins/ansible/ansible/InventoryList.java index 4de139c..0d70f00 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/ansible/InventoryList.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/ansible/InventoryList.java @@ -8,8 +8,6 @@ import java.util.Map; import java.util.Optional; -import static java.lang.String.format; - @Data public class InventoryList { @@ -91,11 +89,10 @@ public enum NodeTag { HOSTNAME { @Override - public void handle(NodeEntryImpl node, Map tags) throws ResourceModelSourceException{ + public void handle(NodeEntryImpl node, Map tags) { final List hostnames = List.of("hostname", "ansible_host", "ansible_ssh_host"); String nameTag = InventoryList.findTag(hostnames, tags); - node.setHostname(Optional.ofNullable(nameTag) - .orElseThrow(() -> new ResourceModelSourceException(format(ERROR_MISSING_TAG, hostnames)))); + Optional.ofNullable(nameTag).ifPresent(node::setHostname); } }, USERNAME { diff --git a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java index db252f8..d6f89da 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java @@ -689,6 +689,8 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB node.setHostname(hostName); node.setNodename(hostName); Map nodeValues = InventoryList.getType(hostNode.getValue()); + + InventoryList.tagHandle(NodeTag.HOSTNAME, node, nodeValues); InventoryList.tagHandle(NodeTag.USERNAME, node, nodeValues); InventoryList.tagHandle(NodeTag.OS_FAMILY, node, nodeValues); InventoryList.tagHandle(NodeTag.OS_NAME, node, nodeValues); @@ -696,6 +698,12 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB InventoryList.tagHandle(NodeTag.OS_VERSION, node, nodeValues); InventoryList.tagHandle(NodeTag.DESCRIPTION, node, nodeValues); + nodeValues.forEach((key, value) -> { + if (value != null) { + node.setAttribute(key, value.toString()); + } + }); + nodes.putNode(node); } }