From e26e27bc53b9138a511205e1dc7a80a747767b47 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Wed, 15 Mar 2023 22:32:18 +0100 Subject: [PATCH] improvements, not tested yet, not published --- README.md | 49 ++------------------- defaults/main.yml | 6 +-- meta/main.yml | 72 ++++++++++--------------------- meta/requirements.yml | 4 ++ molecule/default/requirements.yml | 3 +- tasks/main.yml | 11 +++++ tasks/prerequisites.yml | 13 ++++++ vars/main.yml | 2 + 8 files changed, 60 insertions(+), 100 deletions(-) create mode 100644 meta/requirements.yml create mode 100644 tasks/prerequisites.yml diff --git a/README.md b/README.md index 2ed8084..74310e2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -Hashicorp Consul +Manage pip packages ========= > This repository is only a mirror. Development and testing is done on a private gitlab server. -This role install and configure consul on **debian-based** distributions. +This role enables you to manage python packages on debian-based distributions. It can be used on its own , or be called by other roles the install/remove packages on demand. Requirements ------------ @@ -18,49 +18,6 @@ hashi_consul_install: true # by default, set to true ``` This variable defines if the consul package is to be installed or not before configuring. If you install consul using another task, you can set this to `false`. -```yaml -hashi_consul_start_service: true -``` -This variable defines if the consul service should be started once it has been configured. This is usefull in case you're using this role to build golden images, in which case you might want to only enable the service, to have it start on the next boot (when the image is launched) - -```yaml -hashi_consul_version: latest # by default, set to latest -``` -This variable specifies the version of consul to install when `hashi_consul_install` is set to `true`. The version to specify is the version of the package on the hashicorp repository (`1.14.1-1` for example). - -```yaml -hashi_consul_deploy_method: host # by default, set to host -``` -This variable defines the method of deployment of consul. The `host` method installs the binary directly on the host, and runs consul as a systemd service. The `docker` method install consul as a docker container. -> Currently, only the `host` method is available, the `docker` method will be added later. - -```yaml -hashi_consul_server_enable: true # by default, set to true -hashi_consul_connect_enable: false # by default, set to false -hashi_consul_acl_enabled: false # by default, set to false -``` -These variables enable or disable the server, service mesh and acl functions or consul. - -```yaml -hashi_consul_server: -``` -This variable sets a bunch of configuration parameters for consul. For more information on all of them, please check the [documentation](https://developer.hashicorp.com/consul/docs/agent/config/config-files). I try to name them the same as in the configuration file, so that it is easier to search for it. Most of the defaults in the role are the default values of consul, however, some might differ. - -```yaml -hashi_consul_server_ports: -``` -This variable sets up all of the ports used for consul communications. They default to the consul default values. - -```yaml -hashi_consul_client: -``` -This variable is the list of servers to try to join on startup for agents. This only applies to agents, not servers (see `hashi_consul_server['retry_join']` for servers). - -```yaml -hashi_consul_acl: -``` -This variable sets a bunch of settings regarding the ACLs in consul. YOU NEED TO EDIT IT if you decide to enable ACLs on the cluster (you might want to look into `lookup plugins` to fetch tokens from a secret manager, like [vault](https://docs.ansible.com/ansible/latest/collections/community/hashi_vault/hashi_vault_lookup.html) or [bitwarden](https://docs.ansible.com/ansible/latest/collections/community/general/bitwarden_lookup.html)). - Dependencies ------------ @@ -74,7 +31,7 @@ Including an example of how to use your role (for instance, with variables passe # calling the role inside a playbook with either the default or group_vars/host_vars - hosts: servers roles: - - ednxzu.hashicorp_consul + - ednxzu.manage_pip_packages ``` License diff --git a/defaults/main.yml b/defaults/main.yml index 8176a25..48f5dee 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,6 +3,6 @@ manage_pip_packages_install_python: true manage_pip_packages_install_pip: true manage_pip_packages_list: - - name: nginx - version: latest - state: absent + - name: pip + version_constraint: latest + state: present diff --git a/meta/main.yml b/meta/main.yml index e53d671..3b87c5a 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,53 +1,25 @@ +--- +# meta file for manage_pip_packages galaxy_info: - author: your name - namespace: ednxzu - description: your role description - company: your company (optional) - - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Choose a valid license ID from https://spdx.org - some suggested licenses: - # - BSD-3-Clause (default) - # - MIT - # - GPL-2.0-or-later - # - GPL-3.0-only - # - Apache-2.0 - # - CC-BY-4.0 - license: license (GPL-2.0-or-later, MIT, etc) - - min_ansible_version: 2.1 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. - # To view available platforms and versions (or releases), visit: - # https://galaxy.ansible.com/api/v1/platforms/ - # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. + namespace: 'ednxzu' + role_name: 'manage_pip_packages' + author: 'Bertrand Lanson' + description: 'Package management for python on debian-based distros.' + license: 'license (BSD, MIT)' + min_ansible_version: '2.10' + platforms: + - name: Ubuntu + versions: + - focal + - jammy + - name: Debian + versions: + - bullseye + galaxy_tags: + - 'ubuntu' + - 'debian' + - 'python3' + - 'pip' + - 'packages' dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. diff --git a/meta/requirements.yml b/meta/requirements.yml new file mode 100644 index 0000000..3f1514e --- /dev/null +++ b/meta/requirements.yml @@ -0,0 +1,4 @@ +--- +# meta file for hashicorp_consul +roles: + - name: ednxzu.manage_apt_packages diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index e9320f9..ca250b7 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -1,3 +1,4 @@ --- # requirements file for molecule -roles: [] +roles: + - name: ednxzu.manage_apt_packages diff --git a/tasks/main.yml b/tasks/main.yml index bab3d94..0e6a7d2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,13 @@ --- # task/main file for manage_pip_packages +- name: "Import prerequisites.yml" + ansible.builtin.include_tasks: prerequisites.yml + when: manage_pip_packages_install_python + +- name: "Install/remove required packages" + ansible.builtin.pip: + name: "{{ item.name }}{% if item.version_constraint not in [None, '', 'latest'] %}{{ item.version_constraint }}{% endif %}" + state: "{{ item.state }}" + loop: "{{ manage_pip_packages_list }}" + when: manage_pip_packages_list is defined + and manage_pip_packages_list not in [None, ''] diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml new file mode 100644 index 0000000..f878855 --- /dev/null +++ b/tasks/prerequisites.yml @@ -0,0 +1,13 @@ +--- +# task/prerequisites file for manage_pip_packages +- name: "Install python3 and pip" + ansible.builtin.include_role: + name: ednxzu.manage_apt_packages + vars: + manage_apt_packages_list: + - name: "{{ manage_pip_packages_python3_package_name }}" + version: latest + state: present + - name: "{{ manage_pip_packages_pip3_package_name }}" + version: latest + state: present \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index 1e711f0..61614e9 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,4 @@ --- # vars file for manage_pip_packages +manage_pip_packages_python3_package_name: python3 +manage_pip_packages_pip3_package_name: python3-pip