Fix Set PHP Timezone in The Abbey TVR Role.
authorMatt Birkholz <matt@birchwood-abbey.net>
Sun, 1 Jun 2025 04:29:36 +0000 (22:29 -0600)
committerMatt Birkholz <matt@birchwood-abbey.net>
Sun, 1 Jun 2025 04:29:36 +0000 (22:29 -0600)
/etc/timezone is no longer updated(?).  Use "readlink /etc/localtime",
and do it in the playbook.

README.org
abbey
playbooks/timezone.yml
roles_t/abbey-tvr/tasks/main.yml

index 00b2a39e36a74766a5bac92c45c9536e08964197..cbdf0a80a88fd5eb34e1fc25afb5e298fd84aa98 100644 (file)
@@ -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 800fe3ca81f7e0404ac9d96c486355c4f59c41d1..95fd999ba0e90497fdd1a18b764c7556beed5736 100755 (executable)
--- 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");
 }
 
index de065120e1dacbd6a2e7cc06cfb7d900400064bf..9b7f9583ec236c2787b865bd80b54d137a9a321a 100644 (file)
@@ -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
index f3b90c1fb7fda39517b73fabd73a754a40943663..e538bc24ff3e8f50265e65ecce92bae21fce08b7 100644 (file)
   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