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.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.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/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/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/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) diff --git a/tasks/upgrade.yml b/tasks/upgrade.yml index 33ab116..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: python3.8 + PYTHON: "python{{ python_version | default(__python_version) }}" become: yes become_method: sudo become_user: "{{ netbox_user }}" diff --git a/tasks/variables.yml b/tasks/variables.yml new file mode 100644 index 0000000..341374d --- /dev/null +++ b/tasks/variables.yml @@ -0,0 +1,25 @@ +--- +# 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: 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 }}" + 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 new file mode 100644 index 0000000..491d149 --- /dev/null +++ b/vars/Amazon-2.yml @@ -0,0 +1,4 @@ +--- +__python_version: "3.8" +__python_packages: + - "python{{ python_version | default(__python_version) }}" diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml new file mode 100644 index 0000000..50e6208 --- /dev/null +++ b/vars/Debian-10.yml @@ -0,0 +1,10 @@ +--- +__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. diff --git a/vars/Debian-11.yml b/vars/Debian-11.yml new file mode 100644 index 0000000..d525a91 --- /dev/null +++ b/vars/Debian-11.yml @@ -0,0 +1,7 @@ +--- +__python_version: "3.9" +__python_packages: + - "python{{ python_version | default(__python_version) }}" + - "python3-pip" + - "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 new file mode 100644 index 0000000..6412db8 --- /dev/null +++ b/vars/RedHat-8.yml @@ -0,0 +1,6 @@ +--- +__python_version: "3.8" +__python_packages: + - "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 new file mode 100644 index 0000000..a9ba9d9 --- /dev/null +++ b/vars/Ubuntu-20.yml @@ -0,0 +1,7 @@ +--- +__python_version: "3.8" +__python_packages: + - "python{{ python_version | default(__python_version) }}" + - "python3-pip" + - "python{{ python_version | default(__python_version) }}-venv" + - "python{{ python_version | default(__python_version) }}-dev"