ansible_tasks.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. from collections import namedtuple
  3. from ansible.parsing.dataloader import DataLoader
  4. from ansible.vars import VariableManager
  5. from ansible.inventory import Inventory
  6. from ansible.playbook import Playbook
  7. from ansible.executor.playbook_executor import PlaybookExecutor
  8. from core import Neurone
  9. class Ansible_tasks(Neurone):
  10. def __init__(self, task_file):
  11. Neurone.__init__(self)
  12. Options = namedtuple('Options',
  13. ['connection', 'forks', 'become', 'become_method', 'become_user', 'check', 'listhosts',
  14. 'listtasks', 'listtags', 'syntax', 'module_path'])
  15. variable_manager = VariableManager()
  16. loader = DataLoader()
  17. options = Options(connection='local', forks=100, become=None, become_method=None, become_user=None, check=False,
  18. listhosts=False, listtasks=False, listtags=False, syntax=False, module_path="")
  19. passwords = dict(vault_pass='secret')
  20. inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list='localhost')
  21. variable_manager.set_inventory(inventory)
  22. playbooks = [task_file]
  23. executor = PlaybookExecutor(
  24. playbooks=playbooks,
  25. inventory=inventory,
  26. variable_manager=variable_manager,
  27. loader=loader,
  28. options=options,
  29. passwords=passwords)
  30. executor.run()