From 27d94628bd35e0ed3445a90de174b7c3d3945597 Mon Sep 17 00:00:00 2001 From: Vladimir Botka Date: Mon, 18 Nov 2019 21:09:10 +0100 Subject: [PATCH] Separate installation of Linux and BSD (#182) * Added variable nginx_linux_families: ['Debian', 'RedHat', 'Suse'] * Added variable nginx_bsd_systems: ['FreeBSD', 'NetBSD', 'OpenBSD', 'DragonFlyBSD', 'HardenedBSD'] * Handler started only in "not ansible_check_mode" to avoid --check failure when service hes not been installed yet * Installation of Linux moved to install-oss-linux.yml * Installation of BSD moved to install-oss-bsd.yml * File setup-freebsd.yml deleted --- defaults/main.yml | 20 +++++ handlers/main.yml | 4 +- tasks/opensource/install-oss-bsd.yml | 103 +++++++++++++++++++++++++ tasks/opensource/install-oss-linux.yml | 21 +++++ tasks/opensource/install-oss.yml | 42 ++-------- tasks/opensource/setup-freebsd.yml | 10 --- 6 files changed, 153 insertions(+), 47 deletions(-) create mode 100644 tasks/opensource/install-oss-bsd.yml create mode 100644 tasks/opensource/install-oss-linux.yml delete mode 100644 tasks/opensource/setup-freebsd.yml diff --git a/defaults/main.yml b/defaults/main.yml index 1d5ff47..5ec0f8a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -10,6 +10,10 @@ nginx_start: true # Print NGINX configuration file to terminal after executing playbook. nginx_debug_output: false +# Supported systems +nginx_linux_families: ['Debian', 'RedHat', 'Suse'] +nginx_bsd_systems: ['FreeBSD', 'NetBSD', 'OpenBSD', 'DragonFlyBSD', 'HardenedBSD'] + # Specify which type of NGINX you want to install. # Options are 'opensource' or 'plus'. # Default is 'opensource'. @@ -50,6 +54,22 @@ nginx_repository: https://nginx.org/packages/{{ (nginx_branch == 'mainline') | ternary('mainline/', '') }}sles/{{ ansible_distribution_major_version }} +# Choose to install BSD packages or ports. +# Options are True for packages or False for ports. +# Default is True. +nginx_bsd_install_packages: true + +# Choose to update BSD ports collection. +# Options are True for update or False for do not update. +# Default is True. +nginx_bsd_update_ports: true + +# Choose to install packages built from BSD ports collection if +# available. +# Options are True for use packages or False for do not use packages. +# Default is True. +nginx_bsd_portinstall_use_packages: true + # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. # Only works if 'install_from' is set to 'nginx_repository'. diff --git a/handlers/main.yml b/handlers/main.yml index a8148d2..7919dbd 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,7 +13,9 @@ name: nginx state: reloaded - when: nginx_start | bool + when: + - nginx_start | bool + - not ansible_check_mode - name: "(Handler: All OSs) Start NGINX Amplify Agent" service: diff --git a/tasks/opensource/install-oss-bsd.yml b/tasks/opensource/install-oss-bsd.yml new file mode 100644 index 0000000..c4e4498 --- /dev/null +++ b/tasks/opensource/install-oss-bsd.yml @@ -0,0 +1,103 @@ +--- +- name: "(Install: FreeBSD) Update ports" + block: + + - name: "(Install: FreeBSD) Fetch Ports" + command: portsnap fetch --interactive + args: + creates: /var/db/portsnap/INDEX + + - name: "(Install: FreeBSD) Extract Ports" + command: portsnap extract + args: + creates: /usr/ports + + when: + - ansible_system == 'FreeBSD' + - nginx_bsd_update_ports + +- name: "(Install: FreeBSD)" + block: + + - name: "(Install: FreeBSD) Install NGINX package" + pkgng: + name: "www/nginx{{ nginx_version | default('') }}" + state: present + when: nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: FreeBSD) Install NGINX port" + portinstall: + name: "www/nginx{{ nginx_version | default('') }}" + use_packages: "{{ nginx_bsd_portinstall_use_packages | default(omit) }}" + state: present + when: not nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + when: ansible_system == 'FreeBSD' + +- name: "(Install: OpenBSD)" + block: + + - name: "(Install: OpenBSD) Install NGINX package" + openbsd_pkg: + name: "nginx{{ nginx_version | default('') }}" + build: false + state: present + when: nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: OpenBSD) Install NGINX port" + openbsd_pkg: + name: "nginx{{ nginx_version | default('') }}" + build: true + state: present + when: not nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + when: ansible_system == 'OpenBSD' + +- name: "(Install: NetBSD)" + block: + + - name: "(Install: NetBSD) Install NGINX package" + command: "pkg_add www/nginx{{ nginx_version | default('') }}" + when: nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: NetBSD) Install NGINX port" + fail: + msg: "{{ ansible_system }} Install NGINX port not implemented." + when: not nginx_bsd_install_packages + + when: ansible_system == 'NetBSD' + +- name: "(Install: DragonFlyBSD)" + block: + + - name: "(Install: DragonFlyBSD) Install NGINX package" + command: "pkg install www/nginx{{ nginx_version | default('') }}" + when: nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: DragonFlyBSD) Install NGINX port" + fail: + msg: "{{ ansible_system }} Install NGINX port not implemented." + when: not nginx_bsd_install_packages + + when: ansible_system == 'DragonFlyBSD' + +- name: "(Install: HardenedBSD)" + block: + + - name: "(Install: HardenedBSD) Install NGINX package" + command: "pkg install www/nginx{{ nginx_version | default('') }}" + when: nginx_bsd_install_packages + notify: "(Handler: All OSs) Start NGINX" + + - name: "(Install: HardenedBSD) Install NGINX port" + fail: + msg: "{{ ansible_system }} Install NGINX port not implemented." + when: not nginx_bsd_install_packages + + when: ansible_system == 'HardenedBSD' diff --git a/tasks/opensource/install-oss-linux.yml b/tasks/opensource/install-oss-linux.yml new file mode 100644 index 0000000..a554d6c --- /dev/null +++ b/tasks/opensource/install-oss-linux.yml @@ -0,0 +1,21 @@ +--- +- name: "(Install: Linux) Configure NGINX repo" + block: + + - import_tasks: setup-debian.yml + when: ansible_os_family == "Debian" + + - import_tasks: setup-redhat.yml + when: ansible_os_family == "RedHat" + + - import_tasks: setup-suse.yml + when: ansible_os_family == "Suse" + + when: nginx_install_from == "nginx_repository" + +- name: "(Install: Linux) Install NGINX package" + package: + name: "nginx{{ nginx_version | default('') }}" + state: present + when: ansible_os_family in nginx_linux_families + notify: "(Handler: All OSs) Start NGINX" diff --git a/tasks/opensource/install-oss.yml b/tasks/opensource/install-oss.yml index b9d9c8a..a2b8584 100644 --- a/tasks/opensource/install-oss.yml +++ b/tasks/opensource/install-oss.yml @@ -1,38 +1,8 @@ --- -- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX" - block: +- name: "(Install: OSS Linux)" + import_tasks: install-oss-linux.yml + when: ansible_os_family in nginx_linux_families - - import_tasks: setup-debian.yml - when: ansible_os_family == "Debian" - - - import_tasks: setup-redhat.yml - when: ansible_os_family == "RedHat" - - - import_tasks: setup-suse.yml - when: ansible_os_family == "Suse" - - - import_tasks: setup-freebsd.yml - when: ansible_os_family == "FreeBSD" - - - name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX" - package: - name: "nginx{{ nginx_version | default('') }}" - state: present - when: ansible_os_family != "FreeBSD" - notify: "(Handler: All OSs) Start NGINX" - - - name: "(Install: FreeBSD) Install NGINX" - portinstall: - name: nginx - state: present - when: ansible_os_family == "FreeBSD" - notify: "(Handler: All OSs) Start NGINX" - - when: nginx_install_from == "nginx_repository" - -- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX" - package: - name: "nginx{{ nginx_version | default('') }}" - state: present - when: nginx_install_from == "os_repository" - notify: "(Handler: All OSs) Start NGINX" +- name: "(Install: OSS BSD)" + import_tasks: install-oss-bsd.yml + when: ansible_system in nginx_bsd_systems diff --git a/tasks/opensource/setup-freebsd.yml b/tasks/opensource/setup-freebsd.yml deleted file mode 100644 index fdc1ae5..0000000 --- a/tasks/opensource/setup-freebsd.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: "(Install: FreeBSD) Fetch Ports" - command: portsnap fetch --interactive - args: - creates: /var/db/portsnap/INDEX - -- name: "(Install: FreeBSD) Extract Ports" - command: portsnap extract - args: - creates: /usr/ports