From 65072e68b25f66de9bd7c88d2d021f55461bbfc3 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:08:51 +0200 Subject: [PATCH 01/11] style: space out tasks --- lib/deploy_himlarcli.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index 1fce349..7426ab1 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -19,14 +19,17 @@ - openssl-devel - PyYAML - libffi-devel + - name: "Update {{himlarcli_repo}} with version {{himlarcli_ref}}" git: repo: "{{himlarcli_repo}}" version: "{{himlarcli_ref}}" dest: "{{himlarcli_path}}" force: "{{himlarcli_force_update}}" + - name: Manually create the initial virtualenv for himlarcli command: virtualenv --clear "{{himlarcli_path}}" creates="{{himlarcli_path}}/bin/activate" + - name: Update setuptools pip: state: latest @@ -34,20 +37,26 @@ virtualenv: "{{himlarcli_path}}" chdir: "{{himlarcli_path}}" virtualenv_site_packages: "no" + - name: Upgrade pip command: bin/pip install --upgrade pip chdir={{himlarcli_path}} + - name: Install python modules with pip pip: virtualenv: "{{himlarcli_path}}" requirements: "requirements.txt" chdir: "{{himlarcli_path}}" virtualenv_site_packages: "no" + - name: Run setup.py if himlarcli package is not setup command: bin/python setup.py develop chdir={{himlarcli_path}} creates={{himlarcli_path}}/himlarcli.egg-info + - name: Copy config.ini from remote host fetch: src=/etc/himlarcli/config.ini dest={{himlarcli_path}}/config.ini.{{location}} flat=yes when: '("login" not in inventory_hostname) and location != "vagrant"' + # - name: Run test/deploy.sh # command: "{{himlarcli_path}}/tests/deploy.sh" + - name: Copy user whitelist from /opt/repo copy: src=/opt/repo/secrets/common/whitelist_users.txt dest={{himlarcli_path}}/whitelist_users.txt From df2957d85ec9487515031d130d0bab5dbb5c33dc Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:12:47 +0200 Subject: [PATCH 02/11] use pip module to install/upgrade pip --- lib/deploy_himlarcli.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index 7426ab1..b852818 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -39,7 +39,10 @@ virtualenv_site_packages: "no" - name: Upgrade pip - command: bin/pip install --upgrade pip chdir={{himlarcli_path}} + pip: + name: pip + state: latest + virtualenv: "{{ himlarcli_path }}" - name: Install python modules with pip pip: From ad33c4d56ea3c8ba040c4f591846936fc3a158f4 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:26:24 +0200 Subject: [PATCH 03/11] style manual virtualenv command There's probably a reason why this step was introduced. Would be good to know why. The pip module used next, would create the virtualenv if it was missing. --- lib/deploy_himlarcli.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index b852818..b72b989 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -28,7 +28,9 @@ force: "{{himlarcli_force_update}}" - name: Manually create the initial virtualenv for himlarcli - command: virtualenv --clear "{{himlarcli_path}}" creates="{{himlarcli_path}}/bin/activate" + command: "virtualenv --clear {{ himlarcli_path }}" + args: + creates: "{{ himlarcli_path }}/bin/activate" - name: Update setuptools pip: From 091bd971ff2757be9c8ea78d782dab500e69f9c4 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:29:52 +0200 Subject: [PATCH 04/11] install/upgrade pip in venv before anything else It's better to have the latest supported pip before attempting to install any other packages. --- lib/deploy_himlarcli.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index b72b989..d587618 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -32,6 +32,12 @@ args: creates: "{{ himlarcli_path }}/bin/activate" + - name: Upgrade pip + pip: + name: pip + state: latest + virtualenv: "{{ himlarcli_path }}" + - name: Update setuptools pip: state: latest @@ -40,12 +46,6 @@ chdir: "{{himlarcli_path}}" virtualenv_site_packages: "no" - - name: Upgrade pip - pip: - name: pip - state: latest - virtualenv: "{{ himlarcli_path }}" - - name: Install python modules with pip pip: virtualenv: "{{himlarcli_path}}" From d5cf8a5894bd2cfbfa49128de553ca53f0b811ac Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:34:20 +0200 Subject: [PATCH 05/11] virtualenv_site_packages is no by default From the documentation; Note that if this setting is changed on an already existing virtual environment it will not have any effect, the environment must be deleted and newly created. An already existing venv is also the case, so this shouldn't affect things either way. --- lib/deploy_himlarcli.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index d587618..4aa5ed5 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -44,14 +44,12 @@ name: setuptools virtualenv: "{{himlarcli_path}}" chdir: "{{himlarcli_path}}" - virtualenv_site_packages: "no" - name: Install python modules with pip pip: virtualenv: "{{himlarcli_path}}" requirements: "requirements.txt" chdir: "{{himlarcli_path}}" - virtualenv_site_packages: "no" - name: Run setup.py if himlarcli package is not setup command: bin/python setup.py develop chdir={{himlarcli_path}} creates={{himlarcli_path}}/himlarcli.egg-info From 8221e8ac6c64c62a59af693d95884cad6cf03830 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:39:25 +0200 Subject: [PATCH 06/11] pip install setuptools, drop chdir when using virtualenv, the chdir is not needed --- lib/deploy_himlarcli.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index 4aa5ed5..fa96a4c 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -40,10 +40,9 @@ - name: Update setuptools pip: - state: latest name: setuptools - virtualenv: "{{himlarcli_path}}" - chdir: "{{himlarcli_path}}" + state: latest + virtualenv: "{{ himlarcli_path }}" - name: Install python modules with pip pip: From 0eddf9727f104ba4c7205a2ea06b6bd62c1126c3 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:43:29 +0200 Subject: [PATCH 07/11] venv + full path to requirements = drop chdir --- lib/deploy_himlarcli.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index fa96a4c..b12c820 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -46,9 +46,8 @@ - name: Install python modules with pip pip: - virtualenv: "{{himlarcli_path}}" - requirements: "requirements.txt" - chdir: "{{himlarcli_path}}" + requirements: "{{ himlarcli_path }}/requirements.txt" + virtualenv: "{{ himlarcli_path }}" - name: Run setup.py if himlarcli package is not setup command: bin/python setup.py develop chdir={{himlarcli_path}} creates={{himlarcli_path}}/himlarcli.egg-info From ba2915fa8fbf8311123b6d25c0bb58c1d4ab4e12 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 02:53:41 +0200 Subject: [PATCH 08/11] style setup.py command for himlarcli package --- lib/deploy_himlarcli.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index b12c820..d94d5c6 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -50,7 +50,10 @@ virtualenv: "{{ himlarcli_path }}" - name: Run setup.py if himlarcli package is not setup - command: bin/python setup.py develop chdir={{himlarcli_path}} creates={{himlarcli_path}}/himlarcli.egg-info + command: bin/python setup.py develop + args: + chdir: "{{ himlarcli_path }}" + creates: "{{ himlarcli_path }}/himlarcli.egg-info" - name: Copy config.ini from remote host fetch: src=/etc/himlarcli/config.ini dest={{himlarcli_path}}/config.ini.{{location}} flat=yes From a3a935c0a7d5f3b4e8b02aad5c4329baea472c43 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 03:11:00 +0200 Subject: [PATCH 09/11] fix ansible-lint and yamllint whitespace warnings --- lib/deploy_himlarcli.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index d94d5c6..2b7cca7 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -1,3 +1,4 @@ +--- # # Deploy himlarcli to hosts under himlarcli_path # Verified: This will run under ansible 2.1 @@ -20,12 +21,12 @@ - PyYAML - libffi-devel - - name: "Update {{himlarcli_repo}} with version {{himlarcli_ref}}" + - name: "Update {{ himlarcli_repo }} with version {{ himlarcli_ref }}" git: - repo: "{{himlarcli_repo}}" - version: "{{himlarcli_ref}}" - dest: "{{himlarcli_path}}" - force: "{{himlarcli_force_update}}" + repo: "{{ himlarcli_repo }}" + version: "{{ himlarcli_ref }}" + dest: "{{ himlarcli_path }}" + force: "{{ himlarcli_force_update }}" - name: Manually create the initial virtualenv for himlarcli command: "virtualenv --clear {{ himlarcli_path }}" @@ -56,11 +57,11 @@ creates: "{{ himlarcli_path }}/himlarcli.egg-info" - name: Copy config.ini from remote host - fetch: src=/etc/himlarcli/config.ini dest={{himlarcli_path}}/config.ini.{{location}} flat=yes + fetch: src=/etc/himlarcli/config.ini dest={{ himlarcli_path }}/config.ini.{{ location }} flat=yes when: '("login" not in inventory_hostname) and location != "vagrant"' -# - name: Run test/deploy.sh -# command: "{{himlarcli_path}}/tests/deploy.sh" + # - name: Run test/deploy.sh + # command: "{{himlarcli_path}}/tests/deploy.sh" - name: Copy user whitelist from /opt/repo - copy: src=/opt/repo/secrets/common/whitelist_users.txt dest={{himlarcli_path}}/whitelist_users.txt + copy: src=/opt/repo/secrets/common/whitelist_users.txt dest={{ himlarcli_path }}/whitelist_users.txt From be56e3732bb4ff650f8d36b59c4877cd8c82066c Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 03:14:26 +0200 Subject: [PATCH 10/11] fix yamllint: line too long --- lib/deploy_himlarcli.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index 2b7cca7..bd34e35 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -57,11 +57,16 @@ creates: "{{ himlarcli_path }}/himlarcli.egg-info" - name: Copy config.ini from remote host - fetch: src=/etc/himlarcli/config.ini dest={{ himlarcli_path }}/config.ini.{{ location }} flat=yes + fetch: + src: /etc/himlarcli/config.ini + dest: "{{ himlarcli_path }}/config.ini.{{ location }}" + flat: yes when: '("login" not in inventory_hostname) and location != "vagrant"' # - name: Run test/deploy.sh # command: "{{himlarcli_path}}/tests/deploy.sh" - name: Copy user whitelist from /opt/repo - copy: src=/opt/repo/secrets/common/whitelist_users.txt dest={{ himlarcli_path }}/whitelist_users.txt + copy: + src: /opt/repo/secrets/common/whitelist_users.txt + dest: "{{ himlarcli_path }}/whitelist_users.txt" From a8ca978eb6e89903dd6524d72f2dcc67eb9b2e54 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Sun, 24 Oct 2021 03:22:56 +0200 Subject: [PATCH 11/11] fix ansible-lint: risky-file-permissions --- lib/deploy_himlarcli.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/deploy_himlarcli.yaml b/lib/deploy_himlarcli.yaml index bd34e35..7b7f519 100644 --- a/lib/deploy_himlarcli.yaml +++ b/lib/deploy_himlarcli.yaml @@ -70,3 +70,4 @@ copy: src: /opt/repo/secrets/common/whitelist_users.txt dest: "{{ himlarcli_path }}/whitelist_users.txt" + mode: '644'