Skip to content

Commit

Permalink
Added extra properties comming from ansible inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Abarca committed Jul 8, 2024
1 parent 7d680b1 commit 2dff53e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.Map;
import java.util.Optional;

import static java.lang.String.format;

@Data
public class InventoryList {

Expand Down Expand Up @@ -91,11 +89,10 @@ public enum NodeTag {

HOSTNAME {
@Override
public void handle(NodeEntryImpl node, Map<String, Object> tags) throws ResourceModelSourceException{
public void handle(NodeEntryImpl node, Map<String, Object> tags) {
final List<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,21 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
node.setHostname(hostName);
node.setNodename(hostName);
Map<String, Object> 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);
InventoryList.tagHandle(NodeTag.OS_ARCHITECTURE, node, nodeValues);
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);
}
}
Expand Down

0 comments on commit 2dff53e

Please sign in to comment.