From 8ad7990a3e44e7e4fc1de2124a7cde62e7648ee0 Mon Sep 17 00:00:00 2001 From: Alessandro Duvia Date: Thu, 7 Apr 2022 10:18:15 +0200 Subject: [PATCH 1/8] add support for debian bullseye --- meta/main.yml | 4 ++++ molecule/default/requirements.yml | 2 +- tasks/install.debian.yml | 9 +++++---- tasks/main.yml | 3 +++ tasks/variables.yml | 10 ++++++++++ vars/Debian-10.yml | 6 ++++++ vars/Debian-11.yml | 6 ++++++ vars/Ubuntu-20.yml | 6 ++++++ 8 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 tasks/variables.yml create mode 100644 vars/Debian-10.yml create mode 100644 vars/Debian-11.yml create mode 100644 vars/Ubuntu-20.yml diff --git a/meta/main.yml b/meta/main.yml index 2b57c8e..d9e4ac7 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -18,6 +18,10 @@ galaxy_info: - name: Ubuntu versions: - focal + - name: Debian + versions: + - buster + - bullseye galaxy_tags: - netbox - networking diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index d198b9f..1b958ee 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -5,6 +5,6 @@ roles: - name: geerlingguy.postgresql scm: git src: 'git+https://github.com/geerlingguy/ansible-role-postgresql' - version: 3.1.0 + version: 3.2.1 - name: geerlingguy.redis diff --git a/tasks/install.debian.yml b/tasks/install.debian.yml index e2f2637..b1e4557 100644 --- a/tasks/install.debian.yml +++ b/tasks/install.debian.yml @@ -10,10 +10,6 @@ state: present loop: - git - - python3.8 - - python3-pip - - python3.8-venv - - python3.8-dev - build-essential - libxml2-dev - libxslt1-dev @@ -22,6 +18,11 @@ - libssl-dev - zlib1g-dev +- name: install.debian | install required python packages + ansible.builtin.apt: + name: "{{ python_packages }}" + state: present + - name: install.debian | install Git ansible.builtin.apt: name: git diff --git a/tasks/main.yml b/tasks/main.yml index c893f50..f52bd98 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,7 @@ --- +# Variable configuration. +- include_tasks: variables.yml + - name: Include system packages include_tasks: "install.{{ ansible_os_family | lower }}.yml" args: diff --git a/tasks/variables.yml b/tasks/variables.yml new file mode 100644 index 0000000..a37541c --- /dev/null +++ b/tasks/variables.yml @@ -0,0 +1,10 @@ +--- +# Variable configuration. +- name: Include OS-specific variables (Debian). + ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + when: ansible_os_family == 'Debian' + +- name: Define python_packages. + ansible.builtin.set_fact: + python_packages: "{{ __python_packages | list }}" + when: python_packages is not defined diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml new file mode 100644 index 0000000..8a27427 --- /dev/null +++ b/vars/Debian-10.yml @@ -0,0 +1,6 @@ +--- +__python_packages: + - python3.8 + - python3-pip + - python3.8-venv + - python3.8-dev diff --git a/vars/Debian-11.yml b/vars/Debian-11.yml new file mode 100644 index 0000000..4587e4f --- /dev/null +++ b/vars/Debian-11.yml @@ -0,0 +1,6 @@ +--- +__python_packages: + - python3.9 + - python3-pip + - python3.9-venv + - python3.9-dev diff --git a/vars/Ubuntu-20.yml b/vars/Ubuntu-20.yml new file mode 100644 index 0000000..8a27427 --- /dev/null +++ b/vars/Ubuntu-20.yml @@ -0,0 +1,6 @@ +--- +__python_packages: + - python3.8 + - python3-pip + - python3.8-venv + - python3.8-dev From 4477c52d728c56ae1c830f8301013b4cc7e531ed Mon Sep 17 00:00:00 2001 From: Alessandro Duvia Date: Thu, 7 Apr 2022 15:18:02 +0200 Subject: [PATCH 2/8] refactor to support EL based distro --- tasks/install.amazon.yml | 4 ++-- tasks/install.redhat.yml | 8 +++++--- tasks/variables.yml | 10 ++++++++++ vars/Amazon-2.yml | 2 ++ vars/RedHat-8.yml | 5 +++++ 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 vars/Amazon-2.yml create mode 100644 vars/RedHat-8.yml diff --git a/tasks/install.amazon.yml b/tasks/install.amazon.yml index 1365463..943c9f8 100644 --- a/tasks/install.amazon.yml +++ b/tasks/install.amazon.yml @@ -15,14 +15,14 @@ register: amzn2extras changed_when: amzn2extras is failed with_items: - - python3.8 + - "{{ python_packages }}" - postgresql12 - name: install.amazon | enable required extras ansible.builtin.command: "amazon-linux-extras enable {{ item }} " become: yes with_items: - - python3.8 + - "{{ python_packages }}" - postgresql12 when: not amazon_extras_repo.stat.exists or amzn2extras is failed diff --git a/tasks/install.redhat.yml b/tasks/install.redhat.yml index 3eea52c..0d93625 100644 --- a/tasks/install.redhat.yml +++ b/tasks/install.redhat.yml @@ -10,9 +10,6 @@ loop: - gcc - git - - python38 - - python38-devel - - python3-pip - libxml2-devel - libxslt-devel - libffi-devel @@ -20,6 +17,11 @@ - openssl-devel - redhat-rpm-config +- name: install.redhat | install required python packages + ansible.builtin.yum: + name: "{{ python_packages }}" + state: present + - name: install.redhat | install Git ansible.builtin.yum: name: git diff --git a/tasks/variables.yml b/tasks/variables.yml index a37541c..94b5024 100644 --- a/tasks/variables.yml +++ b/tasks/variables.yml @@ -4,6 +4,16 @@ ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml" when: ansible_os_family == 'Debian' +- name: Include OS-specific variables (RedHat). + ansible.builtin.include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + when: + - ansible_os_family == 'RedHat' + - ansible_distribution != 'Amazon' + +- name: Include OS-specific variables (Amazon). + ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + when: ansible_distribution == 'Amazon' + - name: Define python_packages. ansible.builtin.set_fact: python_packages: "{{ __python_packages | list }}" diff --git a/vars/Amazon-2.yml b/vars/Amazon-2.yml new file mode 100644 index 0000000..cfe4cd8 --- /dev/null +++ b/vars/Amazon-2.yml @@ -0,0 +1,2 @@ +--- +__python_packages: python3.8 diff --git a/vars/RedHat-8.yml b/vars/RedHat-8.yml new file mode 100644 index 0000000..bf2791d --- /dev/null +++ b/vars/RedHat-8.yml @@ -0,0 +1,5 @@ +--- +__python_packages: + - python38 + - python38-devel + - python3-pip From a6a40f9a0fba02b400c63d430c8ffb33fb3512c5 Mon Sep 17 00:00:00 2001 From: Alessandro Duvia Date: Thu, 7 Apr 2022 15:24:58 +0200 Subject: [PATCH 3/8] add python version variables --- tasks/upgrade.yml | 2 +- tasks/variables.yml | 5 +++++ vars/Amazon-2.yml | 3 ++- vars/Debian-10.yml | 9 +++++---- vars/Debian-11.yml | 9 +++++---- vars/RedHat-8.yml | 7 ++++--- vars/Ubuntu-20.yml | 9 +++++---- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/tasks/upgrade.yml b/tasks/upgrade.yml index 33ab116..234c615 100644 --- a/tasks/upgrade.yml +++ b/tasks/upgrade.yml @@ -2,7 +2,7 @@ - name: upgrade | run the upgrade script ansible.builtin.command: "{{ netbox_current_path }}/upgrade.sh" environment: - PYTHON: python3.8 + PYTHON: "{{ python_version }}" become: yes become_method: sudo become_user: "{{ netbox_user }}" diff --git a/tasks/variables.yml b/tasks/variables.yml index 94b5024..341374d 100644 --- a/tasks/variables.yml +++ b/tasks/variables.yml @@ -18,3 +18,8 @@ ansible.builtin.set_fact: python_packages: "{{ __python_packages | list }}" when: python_packages is not defined + +- name: Define python_version. + ansible.builtin.set_fact: + python_version: "{{ __python_version }}" + when: python_version is not defined diff --git a/vars/Amazon-2.yml b/vars/Amazon-2.yml index cfe4cd8..a92f51d 100644 --- a/vars/Amazon-2.yml +++ b/vars/Amazon-2.yml @@ -1,2 +1,3 @@ --- -__python_packages: python3.8 +__python_version: "3.8" +__python_packages: "python{{ python_version }}" diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml index 8a27427..9bad893 100644 --- a/vars/Debian-10.yml +++ b/vars/Debian-10.yml @@ -1,6 +1,7 @@ --- +__python_version: "3.8" __python_packages: - - python3.8 - - python3-pip - - python3.8-venv - - python3.8-dev + - "python{{ python_version }}" + - "python3-pip" + - "python{{ python_version }}-venv" + - "python{{ python_version }}-dev" diff --git a/vars/Debian-11.yml b/vars/Debian-11.yml index 4587e4f..2ad7fd6 100644 --- a/vars/Debian-11.yml +++ b/vars/Debian-11.yml @@ -1,6 +1,7 @@ --- +__python_version: "3.9" __python_packages: - - python3.9 - - python3-pip - - python3.9-venv - - python3.9-dev + - "python{{ python_version }}" + - "python3-pip" + - "python{{ python_version }}-venv" + - "python{{ python_version }}-dev" diff --git a/vars/RedHat-8.yml b/vars/RedHat-8.yml index bf2791d..adce960 100644 --- a/vars/RedHat-8.yml +++ b/vars/RedHat-8.yml @@ -1,5 +1,6 @@ --- +__python_version: "3.8" __python_packages: - - python38 - - python38-devel - - python3-pip + - "python{{ python_version | replace('.','') }}" + - "python{{ python_version | replace('.','') }}-devel" + - "python3-pip" diff --git a/vars/Ubuntu-20.yml b/vars/Ubuntu-20.yml index 8a27427..9bad893 100644 --- a/vars/Ubuntu-20.yml +++ b/vars/Ubuntu-20.yml @@ -1,6 +1,7 @@ --- +__python_version: "3.8" __python_packages: - - python3.8 - - python3-pip - - python3.8-venv - - python3.8-dev + - "python{{ python_version }}" + - "python3-pip" + - "python{{ python_version }}-venv" + - "python{{ python_version }}-dev" From e8752def4d2138c3fda56b6e0367f4067275c293 Mon Sep 17 00:00:00 2001 From: Alessandro Duvia Date: Mon, 11 Apr 2022 17:20:59 +0200 Subject: [PATCH 4/8] add __python_packages default value --- vars/Amazon-2.yml | 2 +- vars/Debian-10.yml | 6 +++--- vars/Debian-11.yml | 6 +++--- vars/RedHat-8.yml | 4 ++-- vars/Ubuntu-20.yml | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vars/Amazon-2.yml b/vars/Amazon-2.yml index a92f51d..f9e2a49 100644 --- a/vars/Amazon-2.yml +++ b/vars/Amazon-2.yml @@ -1,3 +1,3 @@ --- __python_version: "3.8" -__python_packages: "python{{ python_version }}" +__python_packages: "python{{ python_version | default(__python_version) }}" diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml index 9bad893..a9ba9d9 100644 --- a/vars/Debian-10.yml +++ b/vars/Debian-10.yml @@ -1,7 +1,7 @@ --- __python_version: "3.8" __python_packages: - - "python{{ python_version }}" + - "python{{ python_version | default(__python_version) }}" - "python3-pip" - - "python{{ python_version }}-venv" - - "python{{ python_version }}-dev" + - "python{{ python_version | default(__python_version) }}-venv" + - "python{{ python_version | default(__python_version) }}-dev" diff --git a/vars/Debian-11.yml b/vars/Debian-11.yml index 2ad7fd6..d525a91 100644 --- a/vars/Debian-11.yml +++ b/vars/Debian-11.yml @@ -1,7 +1,7 @@ --- __python_version: "3.9" __python_packages: - - "python{{ python_version }}" + - "python{{ python_version | default(__python_version) }}" - "python3-pip" - - "python{{ python_version }}-venv" - - "python{{ python_version }}-dev" + - "python{{ python_version | default(__python_version) }}-venv" + - "python{{ python_version | default(__python_version) }}-dev" diff --git a/vars/RedHat-8.yml b/vars/RedHat-8.yml index adce960..6412db8 100644 --- a/vars/RedHat-8.yml +++ b/vars/RedHat-8.yml @@ -1,6 +1,6 @@ --- __python_version: "3.8" __python_packages: - - "python{{ python_version | replace('.','') }}" - - "python{{ python_version | replace('.','') }}-devel" + - "python{{ python_version | default(__python_version) | replace('.','') }}" + - "python{{ python_version | default(__python_version) | replace('.','') }}-devel" - "python3-pip" diff --git a/vars/Ubuntu-20.yml b/vars/Ubuntu-20.yml index 9bad893..a9ba9d9 100644 --- a/vars/Ubuntu-20.yml +++ b/vars/Ubuntu-20.yml @@ -1,7 +1,7 @@ --- __python_version: "3.8" __python_packages: - - "python{{ python_version }}" + - "python{{ python_version | default(__python_version) }}" - "python3-pip" - - "python{{ python_version }}-venv" - - "python{{ python_version }}-dev" + - "python{{ python_version | default(__python_version) }}-venv" + - "python{{ python_version | default(__python_version) }}-dev" From 19519028598db2f6cf9fd5b1f9f609224d9a82c2 Mon Sep 17 00:00:00 2001 From: Duviful Date: Tue, 19 Apr 2022 15:59:15 +0200 Subject: [PATCH 5/8] fix env variable --- tasks/upgrade.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/upgrade.yml b/tasks/upgrade.yml index 234c615..059f11b 100644 --- a/tasks/upgrade.yml +++ b/tasks/upgrade.yml @@ -2,7 +2,7 @@ - name: upgrade | run the upgrade script ansible.builtin.command: "{{ netbox_current_path }}/upgrade.sh" environment: - PYTHON: "{{ python_version }}" + PYTHON: "python{{ python_version | default(__python_version) }}" become: yes become_method: sudo become_user: "{{ netbox_user }}" From 2788fd2450fb7ad2d461fea97140a34ab4fc0ea3 Mon Sep 17 00:00:00 2001 From: Duviful Date: Tue, 19 Apr 2022 15:59:31 +0200 Subject: [PATCH 6/8] set variables for deb10 --- vars/Debian-10.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml index a9ba9d9..50e6208 100644 --- a/vars/Debian-10.yml +++ b/vars/Debian-10.yml @@ -1,7 +1,10 @@ --- -__python_version: "3.8" +__python_version: "3.7" +# this is the last supported available version of python on debian 10. __python_packages: - "python{{ python_version | default(__python_version) }}" - "python3-pip" - "python{{ python_version | default(__python_version) }}-venv" - "python{{ python_version | default(__python_version) }}-dev" +netbox_version_tag: v3.1.11 +# this is the last supported version of netbox on debian 10. From 7d4158bb87cee0907fdb20435b40ae4937d904cf Mon Sep 17 00:00:00 2001 From: Duviful Date: Tue, 19 Apr 2022 15:59:53 +0200 Subject: [PATCH 7/8] fix error on python version userwarn --- tasks/superusers.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/superusers.yml b/tasks/superusers.yml index 5af2d13..399d4aa 100644 --- a/tasks/superusers.yml +++ b/tasks/superusers.yml @@ -20,5 +20,6 @@ label: "{{ item.username }}" changed_when: '"Superuser created successfully." in result.stdout' failed_when: > + (result.rc != 0) and (result.stderr != '') and ("CommandError: Error: That username is already taken." not in result.stderr) From 79903b5c583257b800d5e11b8eb6204b9113a531 Mon Sep 17 00:00:00 2001 From: Alessandro Duvia Date: Wed, 27 Apr 2022 10:32:04 +0200 Subject: [PATCH 8/8] fix amazonlinux extra interpretation --- vars/Amazon-2.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vars/Amazon-2.yml b/vars/Amazon-2.yml index f9e2a49..491d149 100644 --- a/vars/Amazon-2.yml +++ b/vars/Amazon-2.yml @@ -1,3 +1,4 @@ --- __python_version: "3.8" -__python_packages: "python{{ python_version | default(__python_version) }}" +__python_packages: + - "python{{ python_version | default(__python_version) }}"