daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Jan 11th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ANSIBLE_CFG
  2. [inventory]
  3. enable_plugins = auto, postgrest, host_list, script, yaml, ini
  4. inventory_plugins = plugins/inventory
  5.  
  6. # inventories/my_postgrest.yml
  7. plugin: postgrest
  8.  
  9. # plugins/inventory/postgrest.yml
  10. from __future__ import absolute_import, division, print_function
  11.  
  12. import urllib.parse
  13.  
  14. import requests
  15. from ansible.plugins.inventory import BaseInventoryPlugin
  16.  
  17. DOCUMENTATION = r"""
  18.     name: postgrest
  19.     plugin_type: inventory
  20.     author:
  21.       - Shane Donohoe
  22.     short_description: Pull hosts from postgrest api
  23.     options:
  24.       plugin:
  25.         description: token that states this is a 'postgrest' inventory
  26.         required: True
  27.         choices: ['postgrest']
  28. """
  29.  
  30.  
  31. class InventoryModule(BaseInventoryPlugin):
  32.     NAME = "postgrest"
  33.  
  34.     def verify_file(self, host_list):
  35.         return True
  36.         #  if super(InventoryModule, self).verify_file(path):
  37.             #  if path.endswith(('postgrest.yml', 'postgrest.yaml')):
  38.                 #  return True
  39.         #  return False
  40.  
  41.     def parse(self, inventory, loader, path, cache=False):
  42.         super(InventoryModule, self).parse(inventory, loader, path, cache)
  43.         config = self._read_config_data(self, path)
  44.  
  45.         hosts = ['test1', 'test2', 'test3']
  46.  
  47.         for host in hosts:
  48.             self.inventory.add_host(host)
  49.  
  50. # output
  51. $ ANSIBLE_INVENTORY_PLUGINS="$PWD/plugins/inventory" ansible-playbook -i inventories/my_postgrest.yml test.yml
  52.  [WARNING]:  * Failed to parse /home/shane/inventory_plugin_test/inventories/my_postgrest.yml with auto plugin: _read_config_data() takes 2 positional arguments but 3 were given
  53.  
  54.  [WARNING]:  * Failed to parse /home/shane/inventory_plugin_test/inventories/my_postgrest.yml with postgrest plugin: _read_config_data() takes 2 positional arguments but 3 were given
  55.  
  56.  [WARNING]:  * Failed to parse /home/shane/inventory_plugin_test/inventories/my_postgrest.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
  57.  
  58.  [WARNING]:  * Failed to parse /home/shane/inventory_plugin_test/inventories/my_postgrest.yml with ini plugin: /home/shane/inventory_plugin_test/inventories/my_postgrest.yml:1: Expected key=value host variable assignment, got: postgrest
  59.  
  60.  [WARNING]: Unable to parse /home/shane/inventory_plugin_test/inventories/my_postgrest.yml as an inventory source
  61.  
  62.  [WARNING]: No inventory was parsed, only implicit localhost is available
  63.  
  64.  [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
  65.  
  66.  
  67. PLAY [all] ********************************************************************************************************************************************************************************************************************************************************
  68. skipping: no hosts matched
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top