From: Matt Birkholz Date: Sun, 1 Jun 2025 04:29:36 +0000 (-0600) Subject: Fix Set PHP Timezone in The Abbey TVR Role. X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=38a9b8224655f4e4c098099b02c8db56d9579f8b;p=Network Fix Set PHP Timezone in The Abbey TVR Role. /etc/timezone is no longer updated(?). Use "readlink /etc/localtime", and do it in the playbook. --- diff --git a/README.org b/README.org index 00b2a39..cbdf0a8 100644 --- a/README.org +++ b/README.org @@ -2431,11 +2431,16 @@ bitter complaints. #+CAPTION: [[file:roles_t/abbey-tvr/tasks/main.yml][=roles_t/abbey-tvr/tasks/main.yml=]] #+BEGIN_SRC conf :tangle roles_t/abbey-tvr/tasks/main.yml +- name: Get the local timezone. + shell: readlink /etc/localtime | sed 's,/usr/share/zoneinfo/,,' + delegate_to: localhost + register: timezone + - name: Configure PHP date.timezone. become: yes lineinfile: regexp: date.timezone ?= - line: date.timezone = {{ lookup('file', '/etc/timezone') }} + line: date.timezone = {{ timezone.stdout }} path: "{{ item }}" loop: - /etc/php/8.2/cli/php.ini @@ -3216,13 +3221,7 @@ last host in the previous play. #+CAPTION: [[file:abbey][=abbey=]] #+BEGIN_SRC perl :tangle abbey if ($ARGV[0] eq "tz") { - # my $city = `cat /etc/timezone`; chomp $city; - my $city = (readlink "/etc/localtime"); - $city =~ s,/usr/share/zoneinfo/,,; - my $zone = `date +%Z`; chomp $zone; - print "Setting timezones to $city ($zone).\n"; exec ("ansible-playbook", "-e", "\@Secret/become.yml", - "-e", "zone=$zone", "-e", "city=$city", "playbooks/timezone.yml"); } #+END_SRC @@ -3232,10 +3231,20 @@ if ($ARGV[0] eq "tz") { --- - hosts: core, dvrs, tvrs, webtvs tasks: + - name: Get timezone. + command: date '+%Z' + delegate_to: localhost + register: zone + + - name: Get city. + shell: readlink /etc/localtime | sed 's,/usr/share/zoneinfo/,,' + delegate_to: localhost + register: city + - name: Update timezone. become: yes - command: timedatectl set-timezone {{ city }} - when: ansible_date_time.tz != zone + command: timedatectl set-timezone {{ city.stdout }} + when: ansible_date_time.tz != zone.stdout register: new_tz - hosts: dvrs @@ -3263,7 +3272,7 @@ if ($ARGV[0] eq "tz") { become: yes lineinfile: regexp: date.timezone ?= - line: date.timezone = {{ city }} + line: date.timezone = {{ city.stdout }} path: "{{ item }}" loop: - /etc/php/8.2/cli/php.ini diff --git a/abbey b/abbey index 800fe3c..95fd999 100755 --- a/abbey +++ b/abbey @@ -36,13 +36,7 @@ if ($ARGV[0] eq "versions") { } if ($ARGV[0] eq "tz") { - # my $city = `cat /etc/timezone`; chomp $city; - my $city = (readlink "/etc/localtime"); - $city =~ s,/usr/share/zoneinfo/,,; - my $zone = `date +%Z`; chomp $zone; - print "Setting timezones to $city ($zone).\n"; exec ("ansible-playbook", "-e", "\@Secret/become.yml", - "-e", "zone=$zone", "-e", "city=$city", "playbooks/timezone.yml"); } diff --git a/playbooks/timezone.yml b/playbooks/timezone.yml index de06512..9b7f958 100644 --- a/playbooks/timezone.yml +++ b/playbooks/timezone.yml @@ -1,10 +1,20 @@ --- - hosts: core, dvrs, tvrs, webtvs tasks: + - name: Get timezone. + command: date '+%Z' + delegate_to: localhost + register: zone + + - name: Get city. + shell: readlink /etc/localtime | sed 's,/usr/share/zoneinfo/,,' + delegate_to: localhost + register: city + - name: Update timezone. become: yes - command: timedatectl set-timezone {{ city }} - when: ansible_date_time.tz != zone + command: timedatectl set-timezone {{ city.stdout }} + when: ansible_date_time.tz != zone.stdout register: new_tz - hosts: dvrs @@ -32,7 +42,7 @@ become: yes lineinfile: regexp: date.timezone ?= - line: date.timezone = {{ city }} + line: date.timezone = {{ city.stdout }} path: "{{ item }}" loop: - /etc/php/8.2/cli/php.ini diff --git a/roles_t/abbey-tvr/tasks/main.yml b/roles_t/abbey-tvr/tasks/main.yml index f3b90c1..e538bc2 100644 --- a/roles_t/abbey-tvr/tasks/main.yml +++ b/roles_t/abbey-tvr/tasks/main.yml @@ -52,11 +52,16 @@ when: mythtv.stat.exists notify: Reload Systemd. +- name: Get the local timezone. + shell: readlink /etc/localtime | sed 's,/usr/share/zoneinfo/,,' + delegate_to: localhost + register: timezone + - name: Configure PHP date.timezone. become: yes lineinfile: regexp: date.timezone ?= - line: date.timezone = {{ lookup('file', '/etc/timezone') }} + line: date.timezone = {{ timezone.stdout }} path: "{{ item }}" loop: - /etc/php/8.2/cli/php.ini