Ansible role for running puppet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

puppet_get_hiera_file_list 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python
  2. # Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
  3. #
  4. # This module is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This software is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this software. If not, see <http://www.gnu.org/licenses/>.
  16. DOCUMENTATION = '''
  17. ---
  18. module: puppet_get_hiera_file_list
  19. short_description: Create a list of hiera file paths
  20. description:
  21. - Create a list of hiera file paths
  22. options:
  23. fqdn:
  24. description:
  25. - The ansible fqdn
  26. required: true
  27. groups:
  28. description:
  29. - The groups the host is in
  30. required: true
  31. location:
  32. description:
  33. - Base hiera location in which to look for files
  34. required: true
  35. requirements: [ ]
  36. author: Monty Taylor
  37. '''
  38. def main():
  39. module = AnsibleModule(
  40. argument_spec=dict(
  41. # See AnsibleModule._CHECK_ARGUMENT_TYPES_DISPATCHER for the
  42. # names of valid types
  43. fqdn=dict(required=True, type='str'),
  44. groups=dict(required=True, type='list'),
  45. location=dict(required=True, type='str'),
  46. ),
  47. )
  48. p = module.params
  49. paths = ['group/%s.yaml' % f for f in p['groups'] ]
  50. paths.append('common.yaml')
  51. paths.append('fqdn/%s.yaml' % p['fqdn'])
  52. good_paths = []
  53. for path in paths:
  54. full_path = os.path.join(p['location'], path)
  55. if os.path.exists(full_path):
  56. good_paths.append(path)
  57. module.exit_json(paths=good_paths)
  58. # import module snippets
  59. from ansible.module_utils.basic import *
  60. if __name__ == '__main__':
  61. main()