Created
November 6, 2017 18:28
-
-
Save cbwest3/cb4e9ac16261595a82f8b4ab54629bac to your computer and use it in GitHub Desktop.
Programmatic Ansible 2.4.1 inventory creation
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
def create_inventory(host_list, variable_manager, loader): | |
""" | |
Returns an inventory object for playbook execution. | |
Args: | |
host_list (list): list of IP addresses or hostnames | |
variable_manager (ansible.vars.manager.VariableManager): Ansible variable | |
manager for PlaybookExecutor | |
loader (ansible.parsing.dataloader.DataLoader): Ansible data loader for | |
PlaybookExecutor | |
Returns: ansible.inventory.manager.InventoryManager for PlaybookExecutor | |
""" | |
# create inventory and pass to var manager | |
data = InventoryData() | |
for host in host_list: | |
data.add_host(host) | |
data.reconcile_inventory() | |
inventory = InventoryManager(loader=loader) | |
inventory._inventory = data | |
variable_manager.set_inventory(inventory) | |
return inventory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!