Commit 92d78bf2 authored by Alain Takoudjou's avatar Alain Takoudjou

playbook: add yum roles which optimise yum task by trying to update package only when defined

parent fd0c4951
Pipeline #2086 skipped
--- ---
- name: Install ntp - name: Install ntp
apt: name=ntp state=latest update_cache=yes apt: name=ntp state=latest update_cache=yes cache_valid_time=86400
when: ansible_os_family == "Debian" when: ansible_os_family == "Debian"
- name: Install ntp - include: ../../yum/tasks/main.yml name=ntp cache_valid_time=86400
yum: name=ntp state=latest update_cache=yes
when: ansible_os_family == "RedHat" when: ansible_os_family == "RedHat"
- name: ensure ntp is runing - name: ensure ntp is runing
......
--- ---
- name: Ensure sudo is installed - name: Ensure sudo is installed
apt: name=sudo state=latest update_cache=yes cache_valid_time=3600 apt: name=sudo state=latest update_cache=yes cache_valid_time=86400
when: ansible_os_family == "Debian" when: ansible_os_family == "Debian"
- name: Ensure sudo is installed (yum)
yum: name=sudo state=latest update_cache=yes - include: ../../yum/tasks/main.yml name=sudo cache_valid_time=86400
when: ansible_os_family == "RedHat" when: ansible_os_family == "RedHat"
- name: Ensure /etc/sudoers.d directory is present - name: Ensure /etc/sudoers.d directory is present
......
---
- name: Check when last checked
stat: path=/etc/opt/ansible-yum-latest-{{ name }}
register: check_path
changed_when: false
- name: Calculate age target
shell: echo {{ check_path.stat.mtime|int + cache_valid_time|int }}
register: age_target
when: check_path.stat.exists == true
changed_when: false
- name: Install/update package {{ name }}
yum:
name={{ name }}
state=latest
update_cache=yes
when: check_path.stat.exists == false or age_target.stdout|int <= ansible_date_time.epoch|int
- name: Update Cache File
file:
path=/etc/opt/ansible-yum-latest-{{ name }}
mode=0600
state=touch
when: check_path.stat.exists == false or age_target.stdout|int <= ansible_date_time.epoch|int
changed_when: false
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment