Created
September 18, 2019 13:02
-
-
Save murrahjm/303a776eea22e07a136b2ca3d8c1b24b to your computer and use it in GitHub Desktop.
ansible dynamic inventory script in powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env powershell | |
if ($args -contains '--list') { | |
$output = @{ | |
'all' = @('server1.domain.com', 'server2.domain.com') | |
'webservers' = @('server1.domain.com') | |
'_meta' = @{ | |
'hostvars' = @{ | |
'server1.domain.com' = @{ | |
myvar = 'metavariable' | |
} | |
} | |
} | |
} | |
return $output | convertto-json -depth 99 | |
} | |
elseif ($args -contains '--host') { | |
$output = @{ | |
myvar2 = 'custom variable' | |
} | |
return $output | convertto-json | |
} | |
<# | |
https://docs.ansible.com/ansible/2.5/user_guide/intro_dynamic_inventory.html | |
https://docs.ansible.com/ansible/2.5/dev_guide/developing_inventory.html#developing-inventory | |
supported args shoud be '--list', '--host <hostname>' | |
--list should return a json list of all the supported groups | |
--host <hostname> should return a json list of all the hostvars for the specified hostname | |
optionally return a json body with "_meta" and a list of all the hostvars for all systems | |
(how do you call the above? --host or --list or what?) | |
ansible does a --list first before doing a --host, probably to get the members of the group you're calling so it can then call them with --host | |
the --list output body should have _meta. then ansible will use all those values instead of using --host for each one | |
--host is ignored entirely if _meta exists | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment