From a3c33324582eaa0ed2a5ce421a289ff5ea270ab3 Mon Sep 17 00:00:00 2001 From: Chris Coley <chris@codingallnight.com> Date: Wed, 2 May 2018 16:37:34 -0700 Subject: [PATCH] Adding the ability to install additional prerequisites --- defaults/main.yml | 3 +++ tasks/bootstrap.yml | 31 ++++++++++++++++++++++++++----- tasks/bootstrap_debian.yml | 9 +++++++++ tasks/bootstrap_fedora.yml | 8 ++++++++ tasks/bootstrap_redhat.yml | 9 +++++++++ vars/fedora.yml | 9 +++++++++ 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tasks/bootstrap_debian.yml create mode 100644 tasks/bootstrap_fedora.yml create mode 100644 tasks/bootstrap_redhat.yml create mode 100644 vars/fedora.yml diff --git a/defaults/main.yml b/defaults/main.yml index 3ae95ce..99f43ab 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,6 +3,9 @@ # If blank or undefined, the hostname will not be changed hostname: +# Required packages to support the role tasks +required_utils: [] + # Common packages and utils common_utils: - curl diff --git a/tasks/bootstrap.yml b/tasks/bootstrap.yml index 7405b5c..f3c3b94 100644 --- a/tasks/bootstrap.yml +++ b/tasks/bootstrap.yml @@ -5,11 +5,32 @@ failed_when: false register: result -- block: - - name: Install Python - raw: > - (test -e /etc/redhat-release && yum install -y python) - || (test -e /etc/debian_version && apt-get -y update && apt-get install -y python) +- name: Install Python + raw: > + (test -e /etc/redhat-release && yum install -y python) + || (test -e /etc/debian_version && apt-get -y update && apt-get install -y python) when: result.rc == 1 + +- name: Gather facts to determine host OS + setup: + gather_subset: min + +- name: Gather OS specific vars + include_vars: '{{ item }}' + with_first_found: + - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml + - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml + - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml + - vars/{{ ansible_distribution | lower }}.yml + - vars/{{ ansible_os_family | lower }}.yml + - defaults/main.yml + +- include_tasks: '{{ item }}' + with_first_found: + - tasks/bootstrap_{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml + - tasks/bootstrap_{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml + - tasks/bootstrap_{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml + - tasks/bootstrap_{{ ansible_distribution | lower }}.yml + - tasks/bootstrap_{{ ansible_os_family | lower }}.yml ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/tasks/bootstrap_debian.yml b/tasks/bootstrap_debian.yml new file mode 100644 index 0000000..c725717 --- /dev/null +++ b/tasks/bootstrap_debian.yml @@ -0,0 +1,9 @@ +--- +- name: Install additional OS specific required libraries + apt: + name: '{{ required_utils }}' + state: present + cache_valid_time: 3600 + when: required_utils is defined and required_utils != None and required_utils | length +... +# vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/tasks/bootstrap_fedora.yml b/tasks/bootstrap_fedora.yml new file mode 100644 index 0000000..dc555b5 --- /dev/null +++ b/tasks/bootstrap_fedora.yml @@ -0,0 +1,8 @@ +--- +- name: Install additional OS specific required libraries + dnf: + name: '{{ required_utils }}' + state: present + when: required_utils is defined and required_utils != None and required_utils | length +... +# vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/tasks/bootstrap_redhat.yml b/tasks/bootstrap_redhat.yml new file mode 100644 index 0000000..27de608 --- /dev/null +++ b/tasks/bootstrap_redhat.yml @@ -0,0 +1,9 @@ +--- +- name: Install additional OS specific required libraries + yum: + name: '{{ required_utils }}' + state: present + update_cache: yes + when: required_utils is defined and required_utils != None and required_utils | length +... +# vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/vars/fedora.yml b/vars/fedora.yml new file mode 100644 index 0000000..a7cea7a --- /dev/null +++ b/vars/fedora.yml @@ -0,0 +1,9 @@ +--- +# This file overrides variables set in defaults/main.yml. +# Full documentation of the variables is available in that file. + +required_utils: + - python-dnf + - libselinux-python +... +# vi: set ts=2 sts=2 sw=2 et ft=yaml: -- GitLab