From 33a2d8ded752621ee97a0299275dc8beff27c8b3 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 4 Oct 2018 14:40:07 -0500 Subject: [PATCH] Issue #7: Better package management setup. --- molecule/default/playbook-pip.yml | 12 +++++++++++ molecule/default/requirements.yml | 2 ++ tasks/main.yml | 35 ++++++++++++++++--------------- tasks/setup-Debian.yml | 4 ++-- tasks/setup-Fedora.yml | 4 +++- tasks/setup-RedHat.yml | 5 ++++- tasks/setup-Ubuntu.yml | 6 ++++-- tasks/setup-pip.yml | 5 +++++ 8 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 molecule/default/playbook-pip.yml create mode 100644 molecule/default/requirements.yml create mode 100644 tasks/setup-pip.yml diff --git a/molecule/default/playbook-pip.yml b/molecule/default/playbook-pip.yml new file mode 100644 index 0000000..60e298e --- /dev/null +++ b/molecule/default/playbook-pip.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + become: true + + vars: + ansible_install_method: pip + ansible_install_version_pip: "2.6.2" + + roles: + - role: geerlingguy.pip + - role: geerlingguy.ansible diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..963f84b --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,2 @@ +--- +- role: geerlingguy.pip diff --git a/tasks/main.yml b/tasks/main.yml index 2b3cce6..3fbc2c6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,26 +1,27 @@ --- +- name: Set the package state based on how Ansible is installed. + set_fact: + ansible_package_state: "{{ 'present' if ansible_install_method == 'package' else 'absent' }}" + # Setup/install tasks. -- include_tasks: setup-RedHat.yml +- name: Set up Ansible on RedHat. + include_tasks: setup-RedHat.yml when: - - ansible_install_method == 'package' - ansible_os_family == 'RedHat' - ansible_distribution != 'Fedora' -- include_tasks: setup-Fedora.yml - when: - - ansible_install_method == 'package' - - ansible_distribution == 'Fedora' +- name: Set up Ansible on Fedora. + include_tasks: setup-Fedora.yml + when: ansible_distribution == 'Fedora' -- include_tasks: setup-Ubuntu.yml - when: - - ansible_install_method == 'package' - - ansible_distribution == 'Ubuntu' +- name: Set up Ansible on Ubuntu. + include_tasks: setup-Ubuntu.yml + when: ansible_distribution == 'Ubuntu' -- include_tasks: setup-Debian.yml - when: - - ansible_install_method == 'package' - - ansible_distribution == 'Debian' +- name: Set up Ansible on Debian. + include_tasks: setup-Debian.yml + when: ansible_distribution == 'Debian' -- include_tasks: setup-pip.yml - when: - - ansible_install_method == 'pip' +- name: Set up Ansible using Pip. + include_tasks: setup-pip.yml + when: ansible_install_method == 'pip' diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index 6e50fb6..ff9ec9f 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -9,7 +9,7 @@ when: ansible_distribution_version < 9 - name: Update apt cache. - apt: update_cache=yes cache_valid_time=86400 + apt: update_cache=true cache_valid_time=86400 - name: Set the default_release option for older Debian versions. set_fact: @@ -19,5 +19,5 @@ - name: Install Ansible. apt: name: ansible - state: present + state: "{{ ansible_package_state }}" default_release: "{{ ansible_default_release }}" diff --git a/tasks/setup-Fedora.yml b/tasks/setup-Fedora.yml index 59aeef5..7d56261 100644 --- a/tasks/setup-Fedora.yml +++ b/tasks/setup-Fedora.yml @@ -1,3 +1,5 @@ --- - name: Install Ansible. - package: name=ansible state=present + package: + name: ansible + state: "{{ ansible_package_state }}" diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml index f7d9b70..2f1221d 100644 --- a/tasks/setup-RedHat.yml +++ b/tasks/setup-RedHat.yml @@ -1,3 +1,6 @@ --- - name: Install Ansible. - yum: name=ansible state=present enablerepo=epel + yum: + name: ansible + state: "{{ ansible_package_state }}" + enablerepo: epel diff --git a/tasks/setup-Ubuntu.yml b/tasks/setup-Ubuntu.yml index 13e14aa..2c9b2fa 100644 --- a/tasks/setup-Ubuntu.yml +++ b/tasks/setup-Ubuntu.yml @@ -3,7 +3,9 @@ apt_repository: repo='ppa:ansible/ansible' - name: Update apt cache. - apt: update_cache=yes cache_valid_time=86400 + apt: update_cache=true cache_valid_time=86400 - name: Install Ansible. - apt: name=ansible state=present + apt: + name: ansible + state: "{{ ansible_package_state }}" diff --git a/tasks/setup-pip.yml b/tasks/setup-pip.yml new file mode 100644 index 0000000..a91049b --- /dev/null +++ b/tasks/setup-pip.yml @@ -0,0 +1,5 @@ +--- +- name: Install Ansible via Pip. + pip: + name: ansible + version: "{{ ansible_install_version_pip | default(omit) }}"