2016-12-23 79 views
4

我决定重构一些剧本并尝试新的timezone moduleAnsible时区模块失败(不同操作系统上的不同原因)

我尝试的任务是在手册中给出的例子的完整副本:

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

它未能每个系统我试了。结果流浪机器:

  • 在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": []}

  • 在CentOS 7(centos/7) - 不同的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": []}

  • 在Ubuntu 16.04( ubuntu/xenial64) - 与CentOS相同,与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": []}

我错过了什么吗?是否需要某些依赖项?

+0

'timedatectl'需要'sudo'特权。你可以尝试'时区'与'成为:是'和'成为方法:sudo'? – helloV

+0

就是这样!我被Debian的信息所忽略,然后是操作系统之间的差异,而不是解释消息所说的内容。谢谢。 – techraf

回答

3

timedatectl需要sudo特权。

- name: set timezone to Asia/Tokyo 
    timezone: 
    name: Asia/Tokyo 
    become: yes 
    become_method: sudo 
+0

你碰巧知道'timedatectl'这个自我要求密码的特权提升系统是什么?发出消息“需要身份验证才能设置系统时区”的消息。但是对于Debian来说却失败了。 “* org.freedesktop.PolicyKit1.Authority Interface *”我第一次看到这个。 – techraf

+0

@techraf我刚刚提出了同义词请求。 – helloV

+0

谢谢!只有一票多,混乱结束;-) – techraf

1

检查是否已安装DBUS包(在Ubuntu上测试):

dpkg -l dbus 

,并安装它:

apt-get install -y dbus 

否则你会得到一个错误:

# /usr/bin/timedatectl 
Failed to create bus connection: No such file or directory 
相关问题