9

I decided to refactor some playbooks and give a try to the new timezone module.

The task I try is a verbatim copy of the example given in the manual page:

- name: set timezone to Asia/Tokyo
  timezone:
    name: Asia/Tokyo

It fails on each system I tried. Results for Vagrant machines:

  • On Debian 8 (debian/jessie64):

    TASK [set timezone to Asia/Tokyo] **********************************************
    fatal: [debian]: FAILED! => {"changed": false, "cmd": "/usr/bin/timedatectl set-timezone Asia/Tokyo", "failed": true, "msg": "Failed to set time zone: The name org.freedesktop.PolicyKit1 was not provided by any .service files", "rc": 1, "stderr": "Failed to set time zone: The name org.freedesktop.PolicyKit1 was not provided by any .service files\n", "stdout": "", "stdout_lines": []}

  • On CentOS 7 (centos/7) - different from Debian:

    TASK [set timezone to Asia/Tokyo] **********************************************
    fatal: [centos]: FAILED! => {"changed": false, "cmd": "/usr/bin/timedatectl set-timezone Asia/Tokyo", "failed": true, "msg": "Failed to set time zone: Interactive authentication required.", "rc": 1, "stderr": "Failed to set time zone: Interactive authentication required.\n", "stdout": "", "stdout_lines": []}

  • On Ubuntu 16.04 (ubuntu/xenial64) - same as CentOS, different from Debian:

    TASK [set timezone to Asia/Tokyo] **********************************************
    fatal: [ubuntu]: FAILED! => {"changed": false, "cmd": "/usr/bin/timedatectl set-timezone Asia/Tokyo", "failed": true, "msg": "Failed to set time zone: Interactive authentication required.", "rc": 1, "stderr": "Failed to set time zone: Interactive authentication required.\n", "stdout": "", "stdout_lines": []}

Am I missing something? Is there some dependency required?

Community
  • 1
  • 1
techraf
  • 64,883
  • 27
  • 193
  • 198
  • `timedatectl` needs `sudo` privileges. Can you try `timezone` with `become: yes` and `become_method: sudo`? – helloV Dec 23 '16 at 05:24
  • That's it! I was thrown off balance by the message on Debian and then the difference between OSes instead of interpreting what the message said. Thank you. – techraf Dec 23 '16 at 05:32

2 Answers2

13

timedatectl needs sudo privileges.

- name: set timezone to Asia/Tokyo
  timezone:
    name: Asia/Tokyo
  become: yes
  become_method: sudo
helloV
  • 50,176
  • 7
  • 137
  • 145
  • Do you happen to know what is this self-asking-for-password-privilege-elevating system of `timedatectl`? The one issuing the message "Authentication is required to set the system timezone."? But failing for Debian. "*org.freedesktop.PolicyKit1.Authority Interface*" I'm seeing this for the first time. – techraf Dec 23 '16 at 05:58
  • Thank you! Just one vote more and the mess is over ;-) – techraf Feb 02 '17 at 23:57
1

Check if dbus package is installed (tested on Ubuntu):

dpkg -l dbus

and install it with:

apt-get install -y dbus

else you get a error:

# /usr/bin/timedatectl
Failed to create bus connection: No such file or directory
panticz
  • 2,135
  • 25
  • 16