Ansible 时区模块失败(不同操作系统上的不同原因)

Ansible timezone module fails (different reasons on different OSes)

我决定重构一些剧本并尝试新的 timezone module

我尝试的任务是手册页中给出的示例的逐字副本:

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

它在我尝试过的每个系统上都失败了。 Vagrant 机器的结果:

我错过了什么吗?是否需要一些依赖性?

timedatectl 需要 sudo 权限。

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

检查是否安装了 dbus 包(在 Ubuntu 上测试):

dpkg -l dbus

并安装:

apt-get install -y dbus

否则会出现错误:

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