From 3a5ad8eb66d4fecf6105fdbbb4863a626868ca0a Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Fri, 15 Dec 2023 16:34:12 +0100 Subject: [PATCH] Option to run the installer script once. --- defaults/main.yml | 2 + tasks/r-packages-updater.yml | 110 +++++++++++++++++------------- templates/update_r_packages.sh.j2 | 13 ++++ 3 files changed, 76 insertions(+), 49 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 831de8f..c0e29b0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -44,6 +44,8 @@ r_packages_git_base_dir: /srv/r_updater r_packages_files_prefix: '' r_packages_updater_also_upgrades_installed_packages: true r_packages_updater_for_github_only: true +# Set this to true if you want to run the installer once, and then never after the first execution +r_packages_updater_run_once: false # They need to be flat text files # 1 package per line #r_debian_packages_list_url diff --git a/tasks/r-packages-updater.yml b/tasks/r-packages-updater.yml index 6189b61..a8c8a7b 100644 --- a/tasks/r-packages-updater.yml +++ b/tasks/r-packages-updater.yml @@ -1,46 +1,58 @@ --- -- name: Manage the subversion repository - block: - - name: Create the R packages updater SVN base directory - file: - dest: '{{ r_packages_svn_base_dir }}' - state: directory - +- name: r-packages-updater | Manage the subversion repository when: - r_cran_install_from_sources - r_packages_updater - r_package_updater_via_subversion - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] - -- name: Manage the git repository of the packages lists + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] block: - - name: Remove the R packages updater SVN base directory - file: - dest: '{{ r_packages_svn_base_dir }}/RPackagesManagement' - state: absent - - - name: Create the R packages updater git base directory - file: - dest: '{{ r_packages_git_base_dir }}' + - name: r-packages-updater | Create the R packages updater SVN base directory + ansible.builtin.file: + dest: '{{ r_packages_svn_base_dir }}' state: directory + owner: root + group: root + mode: "0755" +- name: r-packages-updater | Manage the git repository of the packages lists when: - r_cran_install_from_sources - r_packages_updater - r_package_updater_via_git - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] + block: + - name: r-packages-updater | Remove the R packages updater SVN base directory + ansible.builtin.file: + dest: '{{ r_packages_svn_base_dir }}/RPackagesManagement' + state: absent -- block: - - name: Install the R packages updater script - template: + - name: r-packages-updater | Create the R packages updater git base directory + ansible.builtin.file: + dest: '{{ r_packages_git_base_dir }}' + state: directory + owner: root + group: root + mode: "0755" + +- name: r-packages-updater | Scripts that install/update R packages + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] + block: + - name: r-packages-updater | Install the R packages updater script + ansible.builtin.template: src: 'update_r_packages.sh.j2' dest: '/usr/local/bin/update_r_packages' owner: root group: root mode: '0755' - - name: Cron job that installs new R packages, if any - cron: +- name: r-packages-updater | Cron jobs that install/update R packages + when: + - r_cran_install_from_sources + - r_packages_updater + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] + block: + - name: r-packages-updater | Cron job that installs new R packages, if any + ansible.builtin.cron: name: "install new R packages" user: root cron_file: install-r-packages @@ -49,8 +61,8 @@ job: "/usr/local/bin/update_r_packages install >/var/log/install_r_packages 2>&1" state: present - - name: Cron job that upgrades existing R packages and installs new ones, if any - cron: + - name: r-packages-updater | Cron job that upgrades existing R packages and installs new ones, if any + ansible.builtin.cron: name: "Upgrade installed R packages" user: root cron_file: upgrade-r-packages @@ -60,30 +72,30 @@ state: present when: r_packages_updater_also_upgrades_installed_packages - when: - - r_cran_install_from_sources - - r_packages_updater - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] - -- block: - - name: Remove the R packages updater script - file: dest=/usr/local/bin/update_r_packages state=absent - - - name: Remove the R packages updater SVN base directory - file: dest={{ r_packages_svn_base_dir }} state=absent - - - name: Remove the cron job that installs new R packages - file: dest=/etc/cron.d/install-r-packages state=absent - - - name: Remove the cron job that upgrades existing R packages and installs new ones - file: dest=/etc/cron.d/upgrade-r-packages state=absent - +- name: r-packages-updater | Remove the update scripts when: not r_packages_updater - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] + block: + - name: r-packages-updater | Remove the R packages updater SVN base directory + ansible.builtin.file: + dest: "{{ r_packages_svn_base_dir }}" + state: absent -- block: - - name: Disable the cron job that upgrades already installed R packages - file: dest=/etc/cron.d/upgrade-r-packages state=absent + - name: r-packages-updater | Remove the cron job that installs new R packages + ansible.builtin.file: + dest: /etc/cron.d/install-r-packages + state: absent + - name: r-packages-updater | Remove the cron job that upgrades existing R packages and installs new ones + ansible.builtin.file: + dest: /etc/cron.d/upgrade-r-packages + state: absent + +- name: r-packages-updater | Disable the cron job that updates the R packages when: not r_packages_updater_also_upgrades_installed_packages - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] + tags: ['r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater'] + block: + - name: r-packages-updater | Disable the cron job that upgrades already installed R packages + ansible.builtin.file: + dest: /etc/cron.d/upgrade-r-packages + state: absent diff --git a/templates/update_r_packages.sh.j2 b/templates/update_r_packages.sh.j2 index a9c12c5..70f22d3 100644 --- a/templates/update_r_packages.sh.j2 +++ b/templates/update_r_packages.sh.j2 @@ -42,6 +42,11 @@ UPDATER_DEFAULT_BEHAVIOUR="github_only" {% else %} UPDATER_DEFAULT_BEHAVIOUR="everything" {% endif %} +{% if r_packages_updater_run_once %} +INSTALLER_BEHAVIOUR="once" +{% else %} +INSTALLER_BEHAVIOUR="always" +{% endif %} # - debian packages list format: # one package per line DEB_PKGS_SKIP=0 @@ -317,6 +322,14 @@ function r_github_pkgs() { usage get_args init_env +if [ "$INSTALLER_BEHAVIOUR" == "once" ] ; then + if [ -d $R_PKGS_BASE_DIR/$R_PKGS_DIR ] ; then + logger "update_r_packages: The script run once already. Doing nothing." + cleanup + exit 0 + fi +fi + if [ $R_PKGS_FROM_GIT == 'True' ] ; then get_data_files_from_git if [ $GIT_UPDATE_STATUS -ne 1 -a "$ACTION" == "install" ] ; then