From a80d03e5af86f847e35c33d856b390f5b6c74ffe Mon Sep 17 00:00:00 2001 From: Thiago Brito Date: Tue, 16 Aug 2022 14:21:15 -0300 Subject: [PATCH] Fix remote play for backup and restore This change fixes the cases where ansible is looking for vars file on the AnsibleController instead of the remote StarlingX. Also, this file adds requirements.txt and uses it for the tox "venv" setup in order to provide an wasy way for a user to create an environment to remotely run ansible with the same toolset we have on a StarlingX ISO. TEST PLAN PASS remote play for backup PASS local play for backup PASS remote play for restore PASS local play for restore Closes-Bug: #1986691 Signed-off-by: Thiago Brito Change-Id: I27ea61428afafbd12434fca6f7bef4526ee01559 --- .../tasks/kube-extra-save-configuration.yml | 66 ++++++++++++++----- requirements.txt | 4 ++ tox.ini | 3 +- 3 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 requirements.txt diff --git a/playbookconfig/src/playbooks/roles/common/prepare-env/tasks/kube-extra-save-configuration.yml b/playbookconfig/src/playbooks/roles/common/prepare-env/tasks/kube-extra-save-configuration.yml index 940d0c47a..f415759eb 100644 --- a/playbookconfig/src/playbooks/roles/common/prepare-env/tasks/kube-extra-save-configuration.yml +++ b/playbookconfig/src/playbooks/roles/common/prepare-env/tasks/kube-extra-save-configuration.yml @@ -10,8 +10,35 @@ # backup is running. # - name: Read in last kubernetes config values (extraArgs and extraVolumes) - include_vars: - file: "{{ config_permdir }}/last_kube_extra_config_bootstrap.yaml" + block: + - name: Check if load has last_kube_extra_config_bootstrap.yaml + stat: + path: "{{ config_permdir }}/last_kube_extra_config_bootstrap.yaml" + register: load_has_extra_config + + - name: Read last_kube_extra_config_bootstrap.yaml if it exists + block: + + - name: Read last kubernetes config yaml file + command: "cat {{ config_permdir }}/last_kube_extra_config_bootstrap.yaml" + register: result + + - name: Get last kubernetes config facts + set_fact: + last_kube_extra_config: "{{ result.stdout | from_yaml }}" + + - name: Set last kubernetes config facts + set_fact: + apiserver_extra_args: "{{ last_kube_extra_config.apiserver_extra_args }}" + controllermanager_extra_args: "{{ last_kube_extra_config.controllermanager_extra_args }}" + scheduler_extra_args: "{{ last_kube_extra_config.scheduler_extra_args }}" + kubelet_configurations: "{{ last_kube_extra_config.kubelet_configurations }}" + apiserver_extra_volumes: "{{ last_kube_extra_config.apiserver_extra_volumes }}" + controllermanager_extra_volumes: "{{ last_kube_extra_config.controllermanager_extra_volumes }}" + scheduler_extra_volumes: "{{ last_kube_extra_config.scheduler_extra_volumes }}" + + when: load_has_extra_config.stat.exists + when: mode == 'backup' - name: Append kubernetes extra configuration (extraArgs and extraVolumes) @@ -20,17 +47,24 @@ marker: "" create: yes block: | - apiserver_extra_args: - {{ apiserver_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} - controllermanager_extra_args: - {{ controllermanager_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} - scheduler_extra_args: - {{ scheduler_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} - kubelet_configurations: - {{ kubelet_configurations | to_nice_yaml | indent(2, indentfirst=True) }} - apiserver_extra_volumes: - {{ apiserver_extra_volumes | to_yaml | indent(2, indentfirst=True) }} - controllermanager_extra_volumes: - {{ controllermanager_extra_volumes | to_yaml | indent(2, indentfirst=True) }} - scheduler_extra_volumes: - {{ scheduler_extra_volumes | to_yaml | indent(2, indentfirst=True) }} + {% if apiserver_extra_args is defined %} + apiserver_extra_args: {{ apiserver_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if controllermanager_extra_args is defined %} + controllermanager_extra_args: {{ controllermanager_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if scheduler_extra_args is defined %} + scheduler_extra_args: {{ scheduler_extra_args | to_nice_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if kubelet_configurations is defined %} + kubelet_configurations: {{ kubelet_configurations | to_nice_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if apiserver_extra_volumes is defined %} + apiserver_extra_volumes: {{ apiserver_extra_volumes | to_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if controllermanager_extra_volumes is defined %} + controllermanager_extra_volumes: {{ controllermanager_extra_volumes | to_yaml | indent(2, indentfirst=True) }} + {% endif %} + {% if scheduler_extra_volumes is defined %} + scheduler_extra_volumes: {{ scheduler_extra_volumes | to_yaml | indent(2, indentfirst=True) }} + {% endif %} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..dbea900bb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ansible==2.10.7 +jinja2==2.11.3 +markupsafe==1.1.1 +netaddr==0.8.0 diff --git a/tox.ini b/tox.ini index 31324eb78..695092ad3 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,8 @@ setenv = VIRTUAL_ENV={envdir} OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ANSIBLE_LOCAL_TEMP={toxworkdir}/.ansible/tmp -deps = -r{toxinidir}/test-requirements.txt +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt [testenv:linters] basepython = python3