From 2451b5ced341e37fe004b4f36b040a55a97ce03e Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 4 Mar 2021 13:38:44 +0100 Subject: Fixed stupid ansible python sucks silent name collision --- README | 2 +- action_plugins/borg_init.py | 25 +++++++++++++++++++++++++ action_plugins/init.py | 23 ----------------------- tasks/main.yml | 6 +++--- 4 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 action_plugins/borg_init.py delete mode 100644 action_plugins/init.py diff --git a/README b/README index 2c5e078..45a64d3 100644 --- a/README +++ b/README @@ -15,7 +15,7 @@ Here are some job examples : - { name: mysqldump, command_to_pipe: "/usr/bin/mysqldump -h {{ mysql_server }} -u{{ ansible_hostname }} -p{{ ansible_local.mysql_client.password }} --single-transaction --add-drop-database -B {{ ansible_hostname }}" } - { name: gitea, path: "/tmp/gitea.zip", pre_command: "echo '/usr/local/sbin/gitea -C /etc/gitea -c /etc/gitea/app.ini dump -f /tmp/gitea.zip' | su -l _gitea", post_command: "rm -f /tmp/gitea.zip" } -There is an action plugin that parses the borg_server entries from all hosts and set a flag to True in adyxax['is_borg_server'] for any machine specified as a backup target +There is an action plugin that parses the borg_server entries from all host_vars and set the borg.is_server fact to True for any machine specified as a backup target Usefull commands: ================= diff --git a/action_plugins/borg_init.py b/action_plugins/borg_init.py new file mode 100644 index 0000000..1775271 --- /dev/null +++ b/action_plugins/borg_init.py @@ -0,0 +1,25 @@ +from ansible.plugins.action import ActionBase + + +class ActionModule(ActionBase): + def run(self, tmp=None, task_vars=None): + if task_vars is None: + task_vars = dict() + result = super(ActionModule, self).run(tmp, task_vars) + result['changed'] = False + result['failed'] = False + + is_server = False + + for hostname, hostvars in task_vars['hostvars'].items() : + if 'borg_server' in hostvars.keys() and hostvars['borg_server'] == task_vars['ansible_host']: + is_server = True + + result['ansible_facts'] = { + 'borg': { + 'is_server': is_server, + } + } + + return result + diff --git a/action_plugins/init.py b/action_plugins/init.py deleted file mode 100644 index a37b109..0000000 --- a/action_plugins/init.py +++ /dev/null @@ -1,23 +0,0 @@ -from ansible.plugins.action import ActionBase - - -class ActionModule(ActionBase): - def run(self, tmp=None, task_vars=None): - if task_vars is None: - task_vars = dict() - result = super(ActionModule, self).run(tmp, task_vars) - result['changed'] = False - result['failed'] = False - - is_borg_server = False - - for hostname, hostvars in task_vars['hostvars'].items() : - if 'borg_server' in hostvars.keys() and hostvars['borg_server'] == task_vars['ansible_host']: - is_borg_server = True - - result['ansible_facts'] = { - 'is_borg_server': is_borg_server, - } - - return result - diff --git a/tasks/main.yml b/tasks/main.yml index 69df94d..3433cb8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,11 @@ --- -- action: init +- action: borg_init - import_tasks: common.yml - when: is_borg_server or borg_server is defined + when: borg.is_server or borg_server is defined - import_tasks: server.yml - when: is_borg_server + when: borg.is_server - import_tasks: client.yml when: borg_server is defined -- cgit v1.2.3