2016-12-23 78 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 
相關問題