From 5682d4cbea7212d394b379bcd2b5f6de90f613ba Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 20 Jan 2016 12:35:23 -0700 Subject: [PATCH] Use separate codepaths for CentOS 6 vs. 7 Signed-off-by: Zack Cerza --- roles/common/tasks/yum_systems.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/roles/common/tasks/yum_systems.yml b/roles/common/tasks/yum_systems.yml index 931dd81..a7cdb23 100644 --- a/roles/common/tasks/yum_systems.yml +++ b/roles/common/tasks/yum_systems.yml @@ -1,19 +1,35 @@ --- -- name: Get the current timezone +- name: Get the current timezone (RHEL/CentOS 6) shell: cut -d'"' -f2 /etc/sysconfig/clock + when: ansible_distribution_major_version == "6" register: current_tz changed_when: false tags: - timezone -- name: Set the timezone +- name: Get the current timezone (RHEL/CentOS 7) + shell: 'timedatectl | grep Timezone | sed -e "s/.*: \(.*\) (.*/\1/"' + when: ansible_distribution_major_version == "7" + register: current_tz + changed_when: false + tags: + - timezone + +- name: Set the timezone (RHEL/CentOS 6) file: src: /usr/share/zoneinfo/{{ timezone }} dest: /etc/localtime state: link force: yes # Default is used below to avoid breaking check mode - when: current_tz.stdout|default("") != timezone + when: ansible_distribution_major_version == "6" and current_tz.stdout|default("") != timezone + tags: + - timezone + +- name: Set the timezone (RHEL/CentOS 7) + command: timedatectl set-timezone {{ timezone }} + # Default is used below to avoid breaking check mode + when: ansible_distribution_major_version == "7" and current_tz.stdout|default("") != timezone tags: - timezone -- 2.39.5