From 2f7467448698d750ad35ebd5b94b9fc5811d2a7c Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Thu, 24 Aug 2023 23:23:51 +0200 Subject: [PATCH] tests should pass now --- README.md | 24 +++++++++++++++++-- defaults/main.yml | 3 ++- defaults/manage_pipx_packages.yml.sample | 8 +++++++ molecule/default/verify.yml | 10 ++++---- .../with_custom_packages/group_vars/all.yml | 1 + molecule/with_custom_packages/verify.yml | 2 ++ tasks/main.yml | 1 + 7 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 defaults/manage_pipx_packages.yml.sample diff --git a/README.md b/README.md index 17d802b..3d44b3e 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,29 @@ Role Variables Available variables are listed below, along with default values. A sample file for the default values is available in `default/manage_pipx_packages.yml.sample` in case you need it for any `group_vars` or `host_vars` configuration. ```yaml -your_defaults_here: default_value # by default, set to default_value +manage_pipx_packages_install_prereqs: true # by default, set to true ``` -A quick description of the variable, what it does, and how to use it. +This variable defines if the prerequisites for the role should be installed. This should be left to true, unless you install python and pipx from another role prior to running this one. + +```yaml +manage_pipx_packages_home: "/opt/pipx" # by default, set to /opt/pipx +``` +This variable define where the pipx packages should be installed. By default, this is a generic path, in order to not tie the installs to a specific user. + +```yaml +manage_pipx_packages_path: "/usr/local/bin" # by default, set to /usr/local/bin +``` +This variable defines the path on which to make the package available. Please note that the actual installation will be done on the `manage_pipx_packages_home` path. The path given here will be simlinked to the installed package. + +```yaml +manage_pipx_packages_list: # by default, set to install ansible-core + - name: ansible-core + version_constraint: latest + state: present +``` +This variable is a list of packages, with their name, desired version and state. `version_constraint` can be multiple constraints,separated by commas (example: `>1.10`, `>1.10,<1.15,!=1.12`,`==1.13`). +[!WARNING] +Test ? Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index af88006..5274e85 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,9 @@ --- # defaults file for manage_pipx_packages manage_pipx_packages_install_prereqs: true +manage_pipx_packages_home: "/opt/pipx" manage_pipx_packages_path: "/usr/local/bin" manage_pipx_packages_list: - - name: ansible-core + - name: ansible-lint version_constraint: latest state: present diff --git a/defaults/manage_pipx_packages.yml.sample b/defaults/manage_pipx_packages.yml.sample new file mode 100644 index 0000000..0aeb038 --- /dev/null +++ b/defaults/manage_pipx_packages.yml.sample @@ -0,0 +1,8 @@ +--- +manage_pipx_packages_install_prereqs: true +manage_pipx_packages_home: "/opt/pipx" +manage_pipx_packages_path: "/usr/local/bin" +manage_pipx_packages_list: + - name: ansible-lint + version_constraint: latest + state: present diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 2867fc8..0efc13a 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -18,10 +18,12 @@ - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' - - name: "Test: packages ansible-core" + - name: "Test: packages ansible-lint" block: - name: "Get pipx installed packages" ansible.builtin.command: "pipx list --json" + environment: + PIPX_HOME: "/opt/pipx" changed_when: false register: pipx_installed_packages @@ -30,12 +32,10 @@ pipx_simple_list: "{{ pipx_simple_list | default({}) | combine({item.key: item.value.metadata.main_package.package_version}) }}" loop: "{{ pipx_installed_packages.stdout | from_json | json_query('venvs') | dict2items }}" - - name: "Verify packages ansible-core" + - name: "Verify packages ansible-lint" ansible.builtin.assert: that: - - pipx_simple_list['yamllint'] is not defined - - pipx_simple_list['ansible-core'] is defined - - pipx_simple_list['vault-cli'] is not defined + - pipx_simple_list['ansible-lint'] is defined - name: "Print installed packages" ansible.builtin.debug: diff --git a/molecule/with_custom_packages/group_vars/all.yml b/molecule/with_custom_packages/group_vars/all.yml index bb28712..8b262da 100644 --- a/molecule/with_custom_packages/group_vars/all.yml +++ b/molecule/with_custom_packages/group_vars/all.yml @@ -1,5 +1,6 @@ --- manage_pipx_packages_install_prereqs: true +manage_pipx_packages_home: "/opt/pipx" manage_pipx_packages_path: "/usr/local/bin" manage_pipx_packages_list: - name: ansible-core diff --git a/molecule/with_custom_packages/verify.yml b/molecule/with_custom_packages/verify.yml index fd60972..e2bba4b 100644 --- a/molecule/with_custom_packages/verify.yml +++ b/molecule/with_custom_packages/verify.yml @@ -22,6 +22,8 @@ block: - name: "Get pipx installed packages" ansible.builtin.command: "pipx list --json" + environment: + PIPX_HOME: "/opt/pipx" changed_when: false register: pipx_installed_packages diff --git a/tasks/main.yml b/tasks/main.yml index 9285053..6f36c4b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,6 +9,7 @@ name: "{{ item.name }}{% if item.version_constraint not in [None, '', 'latest'] %}{{ item.version_constraint }}{% endif %}" state: "{{ item.state }}" environment: + PIPX_HOME: "{{ manage_pipx_packages_home }}" PIPX_BIN_DIR: "{{ manage_pipx_packages_path }}" loop: "{{ manage_pipx_packages_list }}" when: manage_pipx_packages_list is defined