Skip to content

Commit

Permalink
Issue #7: Better package management setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Oct 4, 2018
1 parent c17bf5e commit 33a2d8d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 23 deletions.
12 changes: 12 additions & 0 deletions molecule/default/playbook-pip.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- role: geerlingguy.pip
35 changes: 18 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 2 additions & 2 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -19,5 +19,5 @@
- name: Install Ansible.
apt:
name: ansible
state: present
state: "{{ ansible_package_state }}"
default_release: "{{ ansible_default_release }}"
4 changes: 3 additions & 1 deletion tasks/setup-Fedora.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
- name: Install Ansible.
package: name=ansible state=present
package:
name: ansible
state: "{{ ansible_package_state }}"
5 changes: 4 additions & 1 deletion tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
- name: Install Ansible.
yum: name=ansible state=present enablerepo=epel
yum:
name: ansible
state: "{{ ansible_package_state }}"
enablerepo: epel
6 changes: 4 additions & 2 deletions tasks/setup-Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
5 changes: 5 additions & 0 deletions tasks/setup-pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Install Ansible via Pip.
pip:
name: ansible
version: "{{ ansible_install_version_pip | default(omit) }}"

0 comments on commit 33a2d8d

Please sign in to comment.