From edb7aeda3c70f9849b96e6a5805a4a9379962276 Mon Sep 17 00:00:00 2001 From: lukken <lukken@astron.nl> Date: Fri, 28 Oct 2022 10:10:15 +0200 Subject: [PATCH] L2SS-983: Templates tasks for ansible deploy --- deploy/deploy.yml | 98 ++++++++++++------------- deploy/tasks/check_binary_install.yml | 9 +++ deploy/tasks/update_database_config.yml | 5 ++ deploy/tasks/verify_database_config.yml | 9 +++ 4 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 deploy/tasks/check_binary_install.yml create mode 100644 deploy/tasks/update_database_config.yml create mode 100644 deploy/tasks/verify_database_config.yml diff --git a/deploy/deploy.yml b/deploy/deploy.yml index 5b525fc1e..994487bb4 100644 --- a/deploy/deploy.yml +++ b/deploy/deploy.yml @@ -2,20 +2,22 @@ - name: StationControl Early Deployment hosts: all vars: - default_install_path: ~/git/tango + base_station_config: "LOFAR_ConfigDb.json" + install_path: ~/git/tango + databaseds_port: 10000 tasks: - - name: Register make installation status - command: which make - changed_when: false - failed_when: make_installed.rc not in [0,1] - register: make_installed - - name: Register git installation status - command: which git - changed_when: false - failed_when: git_installed.rc not in [0,1] - register: git_installed + - name: Check make installed + include_tasks: + file: tasks/check_binary_install.yml + vars: + program: make + - name: Check git installed + include_tasks: + file: tasks/check_binary_install.yml + vars: + program: git - name: Register tango directory status - shell: cd {{ default_install_path }} + shell: cd {{ install_path }} args: chdir: ~ changed_when: false @@ -31,19 +33,13 @@ fi exit 0 args: - chdir: "{{ default_install_path }}" + chdir: "{{ install_path }}" changed_when: false failed_when: pending_changes.rc not in [0,1] register: pending_changes +# Several issues with this variable being unset in ansible 2.2 +# where encountered, keep debug in case needed - debug: var=pending_changes - - name: Check make installation status - fail: - msg: "Make does not appear to be installed!" - when: make_installed.rc not in [0] - - name: Check git installation status - fail: - msg: "Git does not appear to be installed!" - when: git_installed.rc not in [0] - name: Check tango directory status fail: msg: "Tango directory appears to be missing!" @@ -56,66 +52,62 @@ changed_when: false shell: "make stop" args: - chdir: "{{ default_install_path }}/docker-compose" + chdir: "{{ install_path }}/docker-compose" # - name: Git Fetch All # changed_when: false # shell: "git fetch --all" # args: -# chdir: "{{ default_install_path }}" +# chdir: "{{ install_path }}" - name: Update Sources changed_when: false shell: "git checkout {{ station_version }}" args: - chdir: "{{ default_install_path }}" + chdir: "{{ install_path }}" - name: Pull Images changed_when: false shell: "make pull" args: - chdir: "{{ default_install_path }}/docker-compose" + chdir: "{{ install_path }}/docker-compose" - name: Build Images changed_when: false shell: "make build" args: - chdir: "{{ default_install_path }}/docker-compose" + chdir: "{{ install_path }}/docker-compose" - name: Start Database changed_when: false shell: "make minimal" args: - chdir: "{{ default_install_path }}/docker-compose" + chdir: "{{ install_path }}/docker-compose" - name: Wait for databaseds ansible.builtin.wait_for: - port: 10000 + port: "{{ databaseds_port }}" delay: 10 - name: Update Base Database Config - changed_when: false - shell: "./sbin/load_ConfigDb.sh CDB/LOFAR_ConfigDb.json" - args: - chdir: "{{ default_install_path }}" - - name: Get Base Database Config - changed_when: false - shell: "./sbin/load_ConfigDb.sh CDB/LOFAR_ConfigDb.json 2>&1" - register: base_dsconfig_result - args: - chdir: "{{ default_install_path }}" + include_tasks: + file: tasks/update_database_config.yml + vars: + database_config: "{{ base_station_config }}" + base_path: "{{ install_path }}" - name: Verify Base Database Config - when: '"No changes needed" in base_dsconfig_result.stdout' - debug: msg="Base database changes stored" + include_tasks: + file: tasks/verify_database_config.yml + vars: + database_config: "{{ base_station_config }}" + base_path: "{{ install_path }}" - name: Update Station Database Config - changed_when: false - shell: "./sbin/load_ConfigDb.sh CDB/stations/{{ station_config }}" - args: - chdir: "{{ default_install_path }}" - - name: Get Station Database Config - changed_when: false - shell: "./sbin/load_ConfigDb.sh CDB/stations/{{ station_config }} 2>&1" - register: station_dsconfig_result - args: - chdir: "{{ default_install_path }}" + include_tasks: + file: tasks/update_database_config.yml + vars: + database_config: "stations/{{ station_config }}" + base_path: "{{ install_path }}" - name: Verify Station Database Config - when: '"No changes needed" in station_dsconfig_result.stdout' - debug: msg="Station database changes stored" + include_tasks: + file: tasks/verify_database_config.yml + vars: + database_config: "stations/{{ station_config }}" + base_path: "{{ install_path }}" - name: Start Station changed_when: false shell: "make start" args: - chdir: "{{ default_install_path }}/docker-compose" + chdir: "{{ install_path }}/docker-compose" diff --git a/deploy/tasks/check_binary_install.yml b/deploy/tasks/check_binary_install.yml new file mode 100644 index 000000000..f114fd87e --- /dev/null +++ b/deploy/tasks/check_binary_install.yml @@ -0,0 +1,9 @@ + - name: Register installation status + command: which {{ program }} + changed_when: false + failed_when: installed.rc not in [0,1] + register: installed + - name: Check installation status + fail: + msg: "{{ program }} does not appear to be installed!" + when: installed.rc not in [0] \ No newline at end of file diff --git a/deploy/tasks/update_database_config.yml b/deploy/tasks/update_database_config.yml new file mode 100644 index 000000000..be321c576 --- /dev/null +++ b/deploy/tasks/update_database_config.yml @@ -0,0 +1,5 @@ + - name: Update Database Config + changed_when: false + shell: "./sbin/load_ConfigDb.sh CDB/{{ database_config }}" + args: + chdir: "{{ base_path }}" \ No newline at end of file diff --git a/deploy/tasks/verify_database_config.yml b/deploy/tasks/verify_database_config.yml new file mode 100644 index 000000000..1df3681e4 --- /dev/null +++ b/deploy/tasks/verify_database_config.yml @@ -0,0 +1,9 @@ + - name: Get Database Config + changed_when: false + shell: "./sbin/load_ConfigDb.sh CDB/{{ database_config }} 2>&1" + register: dsconfig_result + args: + chdir: "{{ base_path }}" + - name: Verify Database Config + when: '"No changes needed" in dsconfig_result.stdout' + debug: msg="Database changes stored" \ No newline at end of file -- GitLab