From e297e82d9bc7f0087d47c2f08b5101e4beae5d88 Mon Sep 17 00:00:00 2001 From: L3D Date: Mon, 31 Jul 2023 16:45:00 +0200 Subject: [PATCH] Create role l3d.packages --- README.md | 70 +++++++++---------------------- defaults/main.yml | 60 +++++--------------------- meta/main.yml | 8 ++-- tasks/keychain.yml | 26 ------------ tasks/main.yml | 18 +------- tasks/packages.yml | 102 ++++++++++++++++++--------------------------- vars/main.yml | 26 ++++-------- 7 files changed, 85 insertions(+), 225 deletions(-) delete mode 100644 tasks/keychain.yml diff --git a/README.md b/README.md index 042ad9c..643ab6d 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,26 @@ +[![Ansible Galaxy](https://ansible.l3d.space/svg/l3d.packages.svg)](https://galaxy.ansible.com/l3d/packages) +[![BSD-3 Clause](https://ansible.l3d.space/svg/l3d.packages_license.svg)](LICENSE) +[![Maintainance](https://ansible.l3d.space/svg/l3d.packages_maintainance.svg)](https://ansible.l3d.space/#l3d.packages) Ansible Role to install packages --------------------- -``` -WARNING: REWRITE -``` +The purpose of this ansible role ist, to install some usefull packages and to give you the option to install some additional packages. +By default it will also add the [ETH Zürich Debian Packages Mirror](https://debian.ethz.ch/debian/). -A base ansible role that should run on common Linux systems. + Variables +----------- -This role adds more package sources to Debian. And installs some useful tools. This role adds more package sources to Debian. And installs some useful tools. The complete list of tools to install can be found in the [vars/main.yml](https://github.com/roles-ansible/ansible_role_base/blob/master/vars/main.yml). +| variable | default value | useage | +| --- | --- | --- | +| ``l3d_pkgs__adding_ethz`` | ``true`` | Adding the swiss ETH package mirror | +| ``l3d_pkgs__package_state`` | ``present`` | Package State, set to ``latest`` to upgrade packages managed by this role | +| ``l3d_pkgs__install_advanced`` | ``false`` | Install some advanced packages like tcpdump, mtr, fio and ethertools. See ``vars/main.yml`` for details | +| ``l3d_pkgs__install_python`` | ``false`` | Install some Python packages like python3-pip. See ``vars/main.yml`` for details | +| ``l3d_pkgs__install_cli`` | ``false`` | Install some CLI packages like htop, ranger and asciinema. See ``vars/main.yml`` for details | +| ``l3d_pkgs__install_extra_packages`` | | List of additional packages to install | +| ``submodules_versioncheck`` | ``false`` | Enable simple versioncheck to prevent running old versions of this role | -Optionally you can also set vim as the default editor and update all packages to ``latest``. - - -### variables: - -For a complete overview of all variables have a deeper look into the ``vars`` nd the ``defaults`` Folder!. - -```yml ---- -# install these additional packages -base__extra_packages: [] -# - foo -# - bar - -# should we add additional package source? -base__add_ethz: true - -# add nonfree/firmware packages? -base__pkg_non_free_firmware: true -base__pkg_contrib: true - -# add security repo -base__pkg_security: true - -# add Debian Volatile -base__pkg_updates: true - -# optionaly print some OS vars -base__print_os_vars: false - -# choose latest or present for package state -# set this to latest for updating all packages! -base__package_state: 'present' - -# should we update all packages? -base__upgrade_packages_to_latest_version: false - -# install keychain (ssh agent) -base__install_keychain: true - -# install vim (comand line editor) -base__install_vim: true - -# perform a simple versions check (true is recomended) -submodules_versioncheck: false -``` + Contributing +------------- +Please feel free to open a issue or create a pull request. diff --git a/defaults/main.yml b/defaults/main.yml index 5a90c01..20fb998 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,54 +1,16 @@ --- -# install these additional packages -base__extra_packages: [] -# - foo -# - bar +# Adding additional Package Server hosted by ETH Zürich +l3d_pkgs__adding_ethz: true -# should we add additional package source? -base__add_ethz: true -# add nonfree/firmware packages? -base__pkg_non_free_firmware: true -base__pkg_contrib: true -base__pkg_backports: false +# Methods for updating Packages +# set this to latest for updating packages managed by this role +l3d_pkgs__package_state: 'present' -# add security repo -base__pkg_security: true +# Select packages to install +l3d_pkgs__install_advanced: false +l3d_pkgs__install_python: false +l3d_pkgs__install_cli: false +l3d_pkgs__install_extra_packages: [] -# add Debian Volatile -base__pkg_updates: true - -# optionaly print some OS vars -base__print_os_vars: "{{ print_os_vars }}" - -# choose latest or present for package state -# set this to latest for updating all packages! -base__package_state: 'present' - -# should we update all packages? -base__upgrade_packages_to_latest_version: "{{ upgrade_packages_to_latest_version }}" - -# install keycain to have a awesome ssh agent -base__install_keychain: true - -# install vim as awesome command line editor -base__install_vim: true - -# directlink to keychain becaus RHEL do not provide it... -_base__keychain_rpm: 'http://packages.psychotic.ninja/7/base/x86_64/RPMS//keychain-2.8.0-3.el7.psychotic.noarch.rpm' - - -# LEGACY VARS -# ++ WILL BE REMOVED SOON ++ -# add eth zurich apt source - -# do we want the latest package version or just upgrade manually? -upgrade_packages_to_latest_version: false - -# print os variables -print_os_vars: false - -# mailx for debian (recomended for unattended_upgrades role -base__install_mailx: true - -# version management +# Optional perform simple Versionscheck submodules_versioncheck: false diff --git a/meta/main.yml b/meta/main.yml index 546ebf1..c726944 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,8 +1,8 @@ --- galaxy_info: author: l3d - description: Ansible role to install some base packages and make some base configuration on all common linux systems - role_name: base + description: Ansible role to install some base packages on your linux systems + role_name: packages license: MIT min_ansible_version: "2.12" platforms: @@ -19,8 +19,10 @@ galaxy_info: galaxy_tags: - base - packages - - default - apt + - dnf + - cli + - packman - sources - linux dependencies: [] diff --git a/tasks/keychain.yml b/tasks/keychain.yml deleted file mode 100644 index 6bbcc4f..0000000 --- a/tasks/keychain.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- name: Update apt cache - become: true - ansible.builtin.apt: - cache_valid_time: 3600 - update_cache: true - when: - - ansible_pkg_mgr == "apt" - -- name: Install keychain to support ssh agent - become: true - ansible.builtin.package: - name: keychain - state: "{{ base__package_state }}" - when: - - ansible_os_family != 'RedHat' - -- name: Install keychain on centos - become: true - ansible.builtin.yum: - name: - - "{{ _base__keychain_rpm }}" - - libselinux-python - state: "{{ base__package_state }}" - when: - - ansible_os_family == 'RedHat' and ansible_distribution_version | float <= 7 diff --git a/tasks/main.yml b/tasks/main.yml index ed22e4f..f4e4b18 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,12 +9,12 @@ - name: Adding additional apt sources (optional) ansible.builtin.include_tasks: sources_ethz.yml when: - - base__add_ethz | bool + - l3d_pkgs__adding_ethz | bool - ansible_architecture == 'x86_64' - ansible_distribution == 'Debian' and ansible_distribution_version | float >= 8 - ansible_pkg_mgr == "apt" -- name: Install some recomended packages +- name: Install packages based on selection ansible.builtin.include_tasks: packages.yml - name: Upgrade all packages to latest @@ -24,17 +24,3 @@ state: "{{ base__package_state }}" when: - base__upgrade_packages_to_latest_version | bool - -# - name: Optional configure editor -# ansible.builtin.include_tasks: editor.yml -# when: base__install_vim | bool -# -# - name: Optional install keychain -# ansible.builtin.include_tasks: keychain.yml -# when: base__install_keychain | bool -# -# - name: Install optional packages -# become: true -# ansible.builtin.package: -# name: "{{ base__extra_packages }}" -# state: present diff --git a/tasks/packages.yml b/tasks/packages.yml index 8d4cfe2..d69d224 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -1,5 +1,5 @@ --- -- name: Update apt repo-cache for debian/ubuntu +- name: Update apt repo-cache on debian/ubuntu hosts become: true ansible.builtin.apt: update_cache: true @@ -7,72 +7,52 @@ when: - ansible_pkg_mgr == "apt" -- name: Update dnf repo-cache RHEL/Fedora +- name: Update dnf repo-cache on RHEL/Fedora hosts become: true ansible.builtin.dnf: update_cache: true when: - ansible_os_family == 'RedHat' and ansible_distribution_version | float >= 8 -- name: Install base packages for all operating systems +- name: Create Package installation list + blocks: + - name: Create Package installation list + ansible.builtin.set_fact: + l3d_pkgs__install: "{{ l3d_pkgs__base }}" + + - name: Adding Advances Packages to installation list + ansible.builtin.set_fact: + l3d_pkgs__install: "{{ l3d_pkgs__install | ansible.builtin.combine(l3d_pkgs__advanced) }}" + when: + l3d_pkgs__install_advanced | bool + + - name: Adding Python Packages to installation list + ansible.builtin.set_fact: + l3d_pkgs__install: "{{ l3d_pkgs__install | ansible.builtin.combine(l3d_pkgs__python) }}" + when: + l3d_pkgs__install_python | bool + + - name: Adding CLI Packages to installation list + ansible.builtin.set_fact: + l3d_pkgs__install: "{{ l3d_pkgs__base | ansible.builtin.combine(l3d_pkgs__cli) }}" + when: + l3d_pkgs__install_cli | bool + + - name: Adding extra Packages to installation list + ansible.builtin.set_fact: + l3d_pkgs__install: "{{ l3d_pkgs__base | ansible.builtin.combine(l3d_pkgs__install_extra_packages) }}" + + - name: Show l3d_pkgs__install on verbose run + ansible.builtin.debug: + msg: "{{ l3d_pkgs__install }}" + verbosity: 1 + rescue: + ansible.builtin.fail: + msg: "Error creating list of packages for installation. Created list: {{ l3d_pkgs__install }}" + +- name: Install selected Packages become: true ansible.builtin.package: name: "{{ item }}" - state: "{{ base__package_state }}" - with_items: "{{ base__packages }}" - -- name: Install python3 for all non-legacy systems - become: true - ansible.builtin.package: - name: "{{ base__python3_packages }}" - state: "{{ base__package_state }}" - when: | - ansible_distribution == 'Ubuntu' and ansible_distribution_version | float >= 16.0 or - ansible_os_family == 'RedHat' and ansible_distribution_version | float >= 7 or - ansible_distribution == 'Debian' and ansible_distribution_version | float >= 7 - -# - name: Install python for systems where python3 packages are renamed to python -# become: true -# ansible.builtin.package: -# name: "{{ base__python_packages }}" -# state: "{{ base__package_state }}" -# when: ansible_os_family == 'Archlinux' -# -# - name: Install packages for all non-legacy systems -# become: true -# ansible.builtin.package: -# name: "{{ base__modern_packages }}" -# state: "{{ base__package_state }}" -# when: | -# ansible_distribution == 'Ubuntu' and ansible_distribution_version | float >= 16.0 or -# ansible_os_family == 'RedHat' and ansible_distribution_version | float >= 7 or -# ansible_distribution == 'Debian' and ansible_distribution_version | float >= 8 or -# ansible_os_family == 'Archlinux' -# -# - name: Install packages for all non-legacy Debian/Ububntu systems -# become: true -# ansible.builtin.package: -# name: "{{ base__debian_packages }}" -# state: "{{ base__package_state }}" -# when: | -# ansible_distribution == 'Ubuntu' and ansible_distribution_version | float >= 16.0 or -# ansible_distribution == 'Debian' and ansible_distribution_version | float >= 8 -# -# - name: Install packages for all reasonable non-legacy systems -# become: true -# ansible.builtin.package: -# name: "{{ base__linux_packages }}" -# state: "{{ base__package_state }}" -# when: | -# ansible_distribution == 'Ubuntu' and ansible_distribution_version | float >= 18.0 or -# ansible_distribution == 'Fedora' and ansible_distribution_version | float >= 32 or -# ansible_distribution == 'Debian' and ansible_distribution_version | float >= 9 or -# ansible_os_family == 'Archlinux' -# -# - name: Install mailx on debian -# become: true -# ansible.builtin.package: -# name: -# - bsd-mailx -# state: "{{ base__package_state }}" -# when: ansible_distribution == 'Debian' and ansible_distribution_version | float >= 7 and base__install_mailx | bool + state: "{{ l3d_pkgs__package_state }}" + with_items: "{{ l3d_pkgs__install }}" diff --git a/vars/main.yml b/vars/main.yml index eda9d66..30421e5 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,6 +1,6 @@ --- # must-have packages for all systems -base__packages: +l3d_pkgs__base: - rsync - tmux - sudo @@ -16,14 +16,9 @@ base__packages: - lsof - pwgen -# packages for all non-legacy x86 systems -base__modern_packages: +l3d_pkgs__advanced: - tcpdump - sysstat -# - smartmontools - -# debian/ubuntu packages -base__debian_packages: - debian-goodies - molly-guard - mtr-tiny @@ -36,18 +31,12 @@ base__debian_packages: - python3-apt - ethstatus -# modern python packages where python stands for python3 -base__python_packages: - - python-pip - - python - -# modern python packages -base__python3_packages: +l3d_pkgs__python: - python3-pip + - python3-dev - python3 -# packages for reasonable linux servers (not RHEL/Centos) -base__linux_packages: +l3d_pkgs__cli: - links - ranger - htop @@ -58,9 +47,8 @@ base__linux_packages: - ncdu - atop - asciinema - - youtube-dl - bzip2 - jq -playbook_version_number: 9020 -playbook_version_path: 'base-packages_roles-ansible_github.version' +playbook_version_number: 5 +playbook_version_path: 'l3d.base.packages.version'