Skip to content

Commit

Permalink
Merge pull request #15 from roles-ansible/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
DO1JLR authored Apr 27, 2024
2 parents 43229cf + 3635fbf commit 8dbf8e1
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- .github/
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ By default it will also add the [ETH Zürich Debian Packages Mirror](https://deb

| variable | default value | useage |
| --- | --- | --- |
| ``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 |
| ``l3d_pkgs__package_state`` | ``present`` | Package State, set to ``latest`` to upgrade packages managed by this role |
| ``l3d_pkgs__upgrade_all`` | ``false`` | Can upgrade all packages if ``l3d_pkgs__package_state`` is to ``latest`` and the value is ``true`` |
| ``l3d_pkgs__adding_ethz`` | ``true`` | Adding the swiss ETH package mirror |
| ``l3d_pkgs__ethz_contrib`` | ``true`` | contrib packages contain DFSG-compliant software |
| ``l3d_pkgs__ethz_non_free`` | ``true`` | non-free contains software that does not comply with the DFSG. |
| ``l3d_pkgs__ethz_non_free_firmware`` | ``true`` | contains non-free-firmware packages |
| ``l3d_pkgs__ethz_security`` | ``true`` | Inofficial Debian Security Mirror |
| ``l3d_pkgs__ethz_updates`` | ``true`` | Updates Mirror |
| ``l3d_pkgs__ethz__backports`` | ``true`` | Backports Mirror |
| ``submodules_versioncheck`` | ``false`` | Enable simple versioncheck to prevent running old versions of this role |
| ``packages__install_advanced`` | ``false`` | Install some advanced packages like tcpdump, mtr, fio and ethertools. See ``vars/main.yml`` for details |
| ``packages__install_python`` | ``false`` | Install some Python packages like python3-pip. See ``vars/main.yml`` for details |
| ``packages__install_cli`` | ``false`` | Install some CLI packages like htop, ranger and asciinema. See ``vars/main.yml`` for details |
| ``packages__install_extra_packages`` | | List of additional packages to install |
| ``packages__package_state`` | ``present`` | Package State, set to ``latest`` to upgrade packages managed by this role |
| ``packages__upgrade_all`` | ``false`` | Can upgrade all packages if ``packages__packages_state`` is to ``latest`` and the value is ``true`` |
| ``packages__adding_ethz`` | ``true`` | Adding the swiss ETH package mirror |
| ``packages__ethz_contrib`` | ``true`` | contrib packages contain DFSG-compliant software |
| ``packages__ethz_non_free`` | ``true`` | non-free contains software that does not comply with the DFSG. |
| ``packages__ethz_non_free_firmware`` | ``true`` | contains non-free-firmware packages |
| ``packages__ethz_security`` | ``true`` | Inofficial Debian Security Mirror |
| ``packages__ethz_updates`` | ``true`` | Updates Mirror |
| ``packages__ethz__backports`` | ``true`` | Backports Mirror |
| ``packages__submodules_versioncheck`` | ``false`` | Enable simple versioncheck to prevent running old versions of this role |

Contributing
-------------
Expand Down
28 changes: 14 additions & 14 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
# Adding additional Package Server hosted by ETH Zürich
l3d_pkgs__adding_ethz: true
l3d_pkgs__ethz_contrib: true
l3d_pkgs__ethz_non_free: true
l3d_pkgs__ethz_non_free_firmware: true
l3d_pkgs__ethz_security: true
l3d_pkgs__ethz_updates: true
l3d_pkgs__ethz__backports: true
packages__adding_ethz: true
packages__ethz_contrib: true
packages__ethz_non_free: true
packages__ethz_non_free_firmware: true
packages__ethz_security: true
packages__ethz_updates: true
packages__ethz__backports: true

# Methods for updating Packages
# set this to latest for updating packages managed by this role
l3d_pkgs__package_state: 'present'
l3d_pkgs__upgrade_all: false
packages__package_state: 'present'
packages__upgrade_all: false

# Select packages to install
l3d_pkgs__install_advanced: false
l3d_pkgs__install_python: false
l3d_pkgs__install_cli: false
l3d_pkgs__install_extra_packages: []
packages__install_advanced: false
packages__install_python: false
packages__install_cli: false
packages__install_extra_packages: []

# Optional perform simple Versionscheck
submodules_versioncheck: false
packages__submodules_versioncheck: false
14 changes: 7 additions & 7 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
- name: Show Information about target OS (on verbose)
ansible.builtin.include_tasks:
file: os_info.yml
file: 'os_info.yml'

- name: Run simple versionscheck (optional)
ansible.builtin.include_tasks:
file: versioncheck.yml
when: submodules_versioncheck | bool
file: 'versioncheck.yml'
when: packages__submodules_versioncheck | bool

- name: Adding additional apt sources (optional)
ansible.builtin.include_tasks:
file: sources_ethz.yml
file: 'sources_ethz.yml'
when:
- l3d_pkgs__adding_ethz | bool
- packages__adding_ethz | bool
- ansible_architecture == 'x86_64'
- ansible_distribution == 'Debian' and ansible_distribution_version | float >= 8
- ansible_pkg_mgr == "apt"

- name: Install packages based on selection
ansible.builtin.include_tasks:
file: packages.yml
file: 'packages.yml'

- name: Upgrade all packages to latest
become: true
ansible.builtin.package:
name: "*"
state: "{{ base__package_state }}"
when:
- l3d_pkgs__upgrade_all | bool
- packages__upgrade_all | bool
26 changes: 13 additions & 13 deletions tasks/os_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
- name: Print used variables # noqa: H500
ansible.builtin.debug:
msg: |
l3d_pkgs__adding_ethz: '{{ l3d_pkgs__adding_ethz }}'
l3d_pkgs__ethz_contrib: '{{ l3d_pkgs__ethz_contrib }}'
l3d_pkgs__ethz_non_free: '{{ l3d_pkgs__ethz_non_free }}'
l3d_pkgs__ethz_non_free_firmware: '{{ l3d_pkgs__ethz_non_free_firmware }}'
l3d_pkgs__ethz_security: '{{ l3d_pkgs__ethz_security }}'
l3d_pkgs__ethz_updates: '{{ l3d_pkgs__ethz_updates }}'
l3d_pkgs__ethz__backports: '{{ l3d_pkgs__ethz__backports }}'
l3d_pkgs__package_state: '{{ l3d_pkgs__package_state }}'
l3d_pkgs__upgrade_all: '{{ l3d_pkgs__upgrade_all }}'
l3d_pkgs__install_advanced: '{{ l3d_pkgs__install_advanced }}'
l3d_pkgs__install_python: '{{ l3d_pkgs__install_python }}'
l3d_pkgs__install_cli: '{{ l3d_pkgs__install_cli }}'
l3d_pkgs__install_extra_packages: '{{ l3d_pkgs__install_extra_packages }}'
packages__adding_ethz: '{{ packages__adding_ethz }}'
packages__ethz_contrib: '{{ packages__ethz_contrib }}'
packages__ethz_non_free: '{{ packages__ethz_non_free }}'
packages__ethz_non_free_firmware: '{{ packages__ethz_non_free_firmware }}'
packages__ethz_security: '{{ packages__ethz_security }}'
packages__ethz_updates: '{{ packages__ethz_updates }}'
packages__ethz__backports: '{{ packages__ethz__backports }}'
packages__package_state: '{{ packages__package_state }}'
packages__upgrade_all: '{{ packages__upgrade_all }}'
packages__install_advanced: '{{ packages__install_advanced }}'
packages__install_python: '{{ packages__install_python }}'
packages__install_cli: '{{ packages__install_cli }}'
packages__install_extra_packages: '{{ packages__install_extra_packages }}'
submodules_versioncheck: '{{ submodules_versioncheck }}'
verbosity: 1
26 changes: 13 additions & 13 deletions tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
block:
- name: Adding Advances Packages to installation list
ansible.builtin.set_fact:
l3d_pkgs__advanced: []
packages__advanced: []
when:
not l3d_pkgs__install_advanced | bool
not packages__install_advanced | bool

- name: Adding Python Packages to installation list
ansible.builtin.set_fact:
ll3d_pkgs__python: []
lpackages__python: []
when:
not l3d_pkgs__install_python | bool
not packages__install_python | bool

- name: Adding CLI Packages to installation list
ansible.builtin.set_fact:
l3d_pkgs__cli: []
packages__cli: []
when:
not l3d_pkgs__install_cli | bool
not packages__install_cli | bool

- name: Combine Lists
ansible.builtin.set_fact:
l3d_pkgs__install: "{{ l3d_pkgs__base + l3d_pkgs__advanced + l3d_pkgs__python + l3d_pkgs__cli + l3d_pkgs__install_extra_packages }}"
packages__install: "{{ packages__base + packages__advanced + packages__python + packages__cli + packages__install_extra_packages }}"

- name: Show l3d_pkgs__install on verbose run # noqa: H500
- name: Show packages__install on verbose run # noqa: H500
ansible.builtin.debug:
msg: "{{ l3d_pkgs__install }}"
msg: "{{ packages__install }}"
verbosity: 1
rescue:
- name: Show l3d_pkgs__install on verbose run # noqa: H500
- name: Show packages__install on verbose run # noqa: H500
ansible.builtin.debug:
msg: "{{ l3d_pkgs__install }}"
msg: "{{ packages__install }}"
verbosity: 1

- name: Error Info
Expand All @@ -56,5 +56,5 @@
become: true
ansible.builtin.package:
name: "{{ item }}"
state: "{{ l3d_pkgs__package_state }}"
loop: "{{ l3d_pkgs__install | flatten(1) }}"
state: "{{ packages__package_state }}"
loop: "{{ packages__install | flatten(1) }}"
24 changes: 12 additions & 12 deletions tasks/sources_ethz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@

- name: Set ETHZ debian packages to main
ansible.builtin.set_fact:
l3d_pkgs__debian_packages_version: 'main contrib'
packages__debian_packages_version: 'main contrib'
when:
- not l3d_pkgs__ethz_contrib | bool
- not l3d_pkgs__ethz_non_free | bool
- not packages__ethz_contrib | bool
- not packages__ethz_non_free | bool

- name: Set ETHZ debian packages to main contrib
ansible.builtin.set_fact:
l3d_pkgs__debian_packages_version: 'main contrib'
packages__debian_packages_version: 'main contrib'
when:
- l3d_pkgs__ethz_contrib | bool
- not l3d_pkgs__ethz_non_free | bool
- packages__ethz_contrib | bool
- not packages__ethz_non_free | bool

- name: Set ETHZ debian packages to main contrib non-free
ansible.builtin.set_fact:
l3d_pkgs__debian_packages_version: 'main contrib non-free'
packages__debian_packages_version: 'main contrib non-free'
when:
- l3d_pkgs__ethz_contrib | bool
- l3d_pkgs__ethz_non_free | bool
- packages__ethz_contrib | bool
- packages__ethz_non_free | bool
- not ansible_distribution_major_version >= '12'

- name: Set ETHZ debian packages to main contrib non-free non-free-firmware
ansible.builtin.set_fact:
l3d_pkgs__debian_packages_version: 'main contrib non-free non-free-firmware'
packages__debian_packages_version: 'main contrib non-free non-free-firmware'
when:
- l3d_pkgs__ethz_contrib | bool
- l3d_pkgs__ethz_non_free | bool
- packages__ethz_contrib | bool
- packages__ethz_non_free | bool
- ansible_distribution_major_version >= '12'

- name: Add ETH zurich apt for Debian
Expand Down
22 changes: 11 additions & 11 deletions tasks/versioncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@
path: '/etc/.ansible-version'
state: directory
mode: "0755"
when: submodules_versioncheck | bool
when: packages__submodules_versioncheck | bool

- name: Check playbook version
become: true
ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ playbook_version_path }}"
src: "/etc/.ansible-version/{{ packages__playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck | bool
when: packages__submodules_versioncheck | bool
failed_when: false

- name: Print remote role version # noqa: H500
ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: submodules_versioncheck | bool
when: packages__submodules_versioncheck | bool

- name: Print locale role version # noqa: H500
ansible.builtin.debug:
msg: "Local role version: '{{ playbook_version_number | string }}'."
when: submodules_versioncheck | bool
msg: "Local role version: '{{ packages__playbook_version_number | string }}'."
when: packages__submodules_versioncheck | bool

- name: Check if your version is outdated
ansible.builtin.fail:
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
msg: "Your ansible module has the version '{{ packages__playbook_version_number }}' and is outdated. You need to update it!"
when:
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck | bool
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= packages__playbook_version_number|int and packages__submodules_versioncheck | bool

- name: Write new version to remote disk
become: true
ansible.builtin.copy:
content: "{{ playbook_version_number }}"
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
content: "{{ packages__playbook_version_number }}"
dest: "/etc/.ansible-version/{{ packages__playbook_version_path }}"
mode: '0644'
when: submodules_versioncheck | bool
when: packages__submodules_versioncheck | bool
tags: skip_ansible_lint_template-instead-of-copy
24 changes: 12 additions & 12 deletions templates/apt.sources.list.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
# https://wiki.debianforum.de/Sources.list

# HTTPS mirror:
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }} {{ l3d_pkgs__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }} {{ l3d_pkgs__debian_packages_version }}
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }} {{ packages__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }} {{ packages__debian_packages_version }}

{% if ansible_distribution_major_version >= '11' %}
deb https://security.debian.ethz.ch/ {{ ansible_distribution_release }}-security {{ l3d_pkgs__debian_packages_version }}
deb-src https://security.debian.ethz.ch/ {{ ansible_distribution_release }}-security {{ l3d_pkgs__debian_packages_version }}
deb https://security.debian.ethz.ch/ {{ ansible_distribution_release }}-security {{ packages__debian_packages_version }}
deb-src https://security.debian.ethz.ch/ {{ ansible_distribution_release }}-security {{ packages__debian_packages_version }}
{% else %}
deb https://security.debian.ethz.ch/ {{ ansible_distribution_release }}/updates {{ l3d_pkgs__debian_packages_version }}
deb-src https://security.debian.ethz.ch/ {{ ansible_distribution_release }}/updates {{ l3d_pkgs__debian_packages_version }}
deb https://security.debian.ethz.ch/ {{ ansible_distribution_release }}/updates {{ packages__debian_packages_version }}
deb-src https://security.debian.ethz.ch/ {{ ansible_distribution_release }}/updates {{ packages__debian_packages_version }}
{% endif %}

{% if l3d_pkgs__ethz_updates %}
{% if packages__ethz_updates %}
# {{ ansible_distribution_release }}-updates, previously known as 'volatile'
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }}-updates {{ l3d_pkgs__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }}-updates {{ l3d_pkgs__debian_packages_version }}
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }}-updates {{ packages__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }}-updates {{ packages__debian_packages_version }}
{% endif %}

{% if l3d_pkgs__ethz__backports %}
{% if packages__ethz__backports %}
# {{ ansible_distribution_release }}-backports
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }}-backports {{ l3d_pkgs__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }}-backports {{ l3d_pkgs__debian_packages_version }}
deb https://debian.ethz.ch/debian {{ ansible_distribution_release }}-backports {{ packages__debian_packages_version }}
deb-src https://debian.ethz.ch/debian {{ ansible_distribution_release }}-backports {{ packages__debian_packages_version }}
{% endif %}

# Contact for proplems with the mirror:
Expand Down
12 changes: 6 additions & 6 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# must-have packages for all systems
l3d_pkgs__base:
packages__base:
- rsync
- tmux
- sudo
Expand All @@ -16,7 +16,7 @@ l3d_pkgs__base:
- lsof
- pwgen

l3d_pkgs__advanced:
packages__advanced:
- tcpdump
- sysstat
- debian-goodies
Expand All @@ -31,12 +31,12 @@ l3d_pkgs__advanced:
- python3-apt
- ethstatus

l3d_pkgs__python:
packages__python:
- python3-pip
- python3-dev
- python3

l3d_pkgs__cli:
packages__cli:
- links
- ranger
- htop
Expand All @@ -51,5 +51,5 @@ l3d_pkgs__cli:
- jq
- zstd

playbook_version_number: 8
playbook_version_path: 'l3d.base.packages.version'
packages__playbook_version_number: 9
packages__playbook_version_path: 'l3d.base.packages.version'

0 comments on commit 8dbf8e1

Please sign in to comment.