#+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
#+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
---
- 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
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
}
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");
}
---
- 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
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
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