Skip to content

Commit

Permalink
Add support for enabling and disabling yum plugins
Browse files Browse the repository at this point in the history
Use tempfile module instead of command+mktemp
Fix ansible 2.5 deprecation warnings
Remove support for RHEL/CentOS 5
Update min_ansible_version to 2.5
  • Loading branch information
Taylor Kimball authored and Taylor Kimball committed Mar 25, 2018
1 parent 2ae31e5 commit 4618cef
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ None
Available variables are listed below, along with default values:

elrepo_dist: "{{ ansible_distribution_major_version }}"
elrepo_disable_plugin: []
elrepo_disablerepo: []
elrepo_enable_plugin: []
elrepo_enablerepo: []
elrepo_kernel: false
elrepo_kernel_version: lt
Expand All @@ -32,6 +34,8 @@ Available variables are listed below, along with default values:
- hosts: servers
roles:
- role: linuxhq.elrepo
elrepo_disable_plugin:
- post-transaction-actions
elrepo_enablerepo:
- epel
elrepo_kernel: true
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
elrepo_dist: "{{ ansible_distribution_major_version }}"
elrepo_disable_plugin: []
elrepo_disablerepo: []
elrepo_enable_plugin: []
elrepo_enablerepo: []
elrepo_kernel: false
elrepo_kernel_version: ml
Expand Down
3 changes: 1 addition & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ galaxy_info:
author: tkimball83
description: RHEL/CentOS - ELRepo Project
license: GPLv3
min_ansible_version: 2.4
min_ansible_version: 2.5
platforms:
- name: EL
versions:
- 5
- 6
- 7
galaxy_tags:
Expand Down
26 changes: 17 additions & 9 deletions tasks/elrepo_kernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
- name: Removing old kernel packages
become: true
yum:
disable_plugin: "{{ elrepo_disable_plugin|join(',') }}"
disablerepo: "{{ elrepo_disablerepo|join(',') }}"
enable_plugin: "{{ elrepo_enable_plugin|join(',') }}"
enablerepo: "{{ elrepo_enablerepo|join(',') }}"
name: "{{ item }}"
state: absent
Expand All @@ -20,7 +22,9 @@
- name: Ensure that the elrepo kernel packages are installed
become: true
yum:
disable_plugin: "{{ elrepo_disable_plugin|join(',') }}"
disablerepo: "{{ elrepo_disablerepo|join(',') }}"
enable_plugin: "{{ elrepo_enable_plugin|join(',') }}"
enablerepo: "{{ elrepo_enablerepo|join(',') }}"
name: "{{ item }}"
state: present
Expand All @@ -33,44 +37,48 @@
- name: Ensure that the kernel tools packages are installed
become: true
yum:
disable_plugin: "{{ elrepo_disable_plugin|join(',') }}"
disablerepo: "{{ elrepo_disablerepo|join(',') }}"
enable_plugin: "{{ elrepo_enable_plugin|join(',') }}"
enablerepo: "{{ elrepo_enablerepo|join(',') }}"
name: "{{ item }}"
state: present
with_items:
- "kernel-{{ elrepo_kernel_version }}-tools"
- "kernel-{{ elrepo_kernel_version }}-tools-libs"
when:
- elrepo_kernel_installed|changed
- elrepo_dist == '7'
- elrepo_kernel_installed is changed

- name: Set the default kernel grub is going to boot (<= el6)
- name: Set the default kernel grub is going to boot (el6)
become: true
lineinfile:
dest: /boot/grub/grub.conf
regexp: '^default='
line: 'default=0'
when:
- elrepo_dist <= '6'
- elrepo_kernel_installed|changed
- name: Set the default kernel grub is going to boot (>= el7)
- elrepo_dist == '6'
- elrepo_kernel_installed is changed

- name: Set the default kernel grub is going to boot (el7)
become: true
command: |
/usr/sbin/grub2-set-default 0
when:
- elrepo_dist >= '7'
- elrepo_kernel_installed|changed
- elrepo_dist == '7'
- elrepo_kernel_installed is changed

- name: Ensure that the required elrepo packages are installed
become: true
yum:
disable_plugin: "{{ elrepo_disable_plugin|join(',') }}"
disablerepo: "{{ elrepo_disablerepo|join(',') }}"
enable_plugin: "{{ elrepo_enable_plugin|join(',') }}"
enablerepo: "{{ elrepo_enablerepo|join(',') }}"
name: "{{ item }}"
state: present
with_items: "{{ elrepo_packages }}"
when:
- elrepo_packages|length > 0
- elrepo_yum|success
- elrepo_yum is success
...
39 changes: 21 additions & 18 deletions tasks/elrepo_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,40 @@
elrepo_version: "6-8.el6"
when: elrepo_dist == '6'

- name: Setting elrepo_version fact (el5)
set_fact:
elrepo_version: "5-5.el5"
when: elrepo_dist == '5'
- name: Attempting to create temporary file
tempfile:
prefix: 'elrepo.'
state: file
suffix: '.rpm'
register: elrepo_tempfile

- name: Generating temporary filename via mktemp
command: |
mktemp -u --suffix .rpm
register: elrepo_mktemp
- name: Temp
debug: var=elrepo_tempfile

- name: Downloading package to temporary location
get_url:
dest: "{{ elrepo_mktemp.stdout }}"
dest: "{{ elrepo_tempfile.path }}"
force: yes
url: "https://www.elrepo.org/elrepo-release-{{ elrepo_version }}.elrepo.noarch.rpm"
register: elrepo_get_url
when: elrepo_mktemp|success
when: elrepo_tempfile is success

- name: Ensure that the elrepo-release package is installed
become: true
yum:
name: "{{ item }}"
state: present
register: elrepo_yum
with_items: "{{ elrepo_mktemp.stdout }}"
when: elrepo_get_url|success
with_items: "{{ elrepo_tempfile.path }}"
when: elrepo_get_url is success

- name: Purging temporary package from filesystem
file:
path: "{{ elrepo_mktemp.stdout }}"
path: "{{ elrepo_tempfile.path }}"
state: absent
when:
- elrepo_mktemp|success
- elrepo_yum|success
- elrepo_tempfile is success
- elrepo_yum is success

- name: Applying elrepo repository configurations
become: true
Expand All @@ -51,24 +52,26 @@
owner: root
group: root
mode: 0644
when: elrepo_yum|success
when: elrepo_yum is success

- name: Ensure that the ELRepo GPG keys are installed
become: true
rpm_key:
key: /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
state: present
when: elrepo_yum|success
when: elrepo_yum is success

- name: Ensure that the required elrepo packages are installed
become: true
yum:
disable_plugin: "{{ elrepo_disable_plugin|join(',') }}"
disablerepo: "{{ elrepo_disablerepo|join(',') }}"
enable_plugin: "{{ elrepo_enable_plugin|join(',') }}"
enablerepo: "{{ elrepo_enablerepo|join(',') }}"
name: "{{ item }}"
state: present
with_items: "{{ elrepo_packages }}"
when:
- elrepo_packages|length > 0
- elrepo_yum|success
- elrepo_yum is success
...
20 changes: 8 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
---
- name: Executing elrepo repository tasks
- name: Attempting to import elrepo tasks
tags: elrepo
import_tasks: elrepo_repository.yml
when:
- ansible_os_family == 'RedHat'

- name: Executing elrepo kernel tasks
tags: elrepo
import_tasks: elrepo_kernel.yml
when:
- ansible_os_family == 'RedHat'
- elrepo_kernel|bool == true
- elrepo_yum|success
block:
- import_tasks: elrepo_repository.yml
- import_tasks: elrepo_kernel.yml
when:
- elrepo_kernel|bool
- elrepo_yum is success
when: ansible_os_family == 'RedHat'
...

0 comments on commit 4618cef

Please sign in to comment.