Last active
May 2, 2019 11:48
-
-
Save kittydoor/a52d4e15627a6684da685a29e2e78aea to your computer and use it in GitHub Desktop.
Gist of problematic dynamic inventory
This file contains 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
DOCUMENTATION = ''' | |
name: dyninv | |
plugin_type: inventory | |
author: | |
- <@kittydoor> | |
short_description: systems inventory source | |
description: | |
- SSH into all hosts provided, and use virsh to discover machines | |
- Group them based on naming convention | |
options: | |
plugin: | |
description: token for this plugin | |
required: True | |
choices: ['dyninv'] | |
hosts: | |
description: list of host ip addr or urls to discover | |
required: True | |
type: list | |
''' | |
EXAMPLES = ''' | |
# File must be named dyninv.yml | |
plugin: dyninv | |
hosts: | |
- d1 | |
- d2 | |
- d3 | |
... | |
''' | |
from ansible.plugins.inventory import BaseInventoryPlugin | |
class InventoryModule(BaseInventoryPlugin): | |
NAME = "dyninv" | |
def parse(self, inventory, loader, path, cache=True): | |
super(InventoryModule, self).parse(inventory, loader, path, cache) | |
self._read_config_data(path) | |
mydata = { | |
"master-aaaa": "10.10.10.2", | |
"node-aaaab": "10.10.10.3", | |
"node-aaaac": "10.10.10.4" | |
} | |
for vm in mydata.items(): | |
self.inventory.add_host(vm.key) | |
self.inventory.set_variable('ansible_host', vm.value) |
This file contains 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
plugin: dyninv | |
hosts: | |
- d1 | |
- d2 | |
- d3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment