LoginSignup
1
0

More than 3 years have passed since last update.

GCEのubuntu 18.04でタイムゾーンをJSTにする

Posted at

久々に10ヶ月前に書いたAnsibleソースをubuntu 18.04に実行したら、以下のエラーが発生した。

エラー内容

fatal: [111.111.111.111]: FAILED! => {"changed": false, "msg": "src file does not exist, use \"force=yes\" if you really want
to create the link: /usr/share/zoneinfo/Japan", "path": "/etc/localtime", "src": "/usr/share/zoneinfo/Japan", "state": "abse
nt"}

該当ソース

- name: setup JST
  file:
    src: /usr/share/zoneinfo/Japan
    dest: /etc/localtime
    state: link

最近は、 timedatectl使うみたいですね。
で、以下のコマンドを調べて、見るとUTCしかない。

$ timedatectl list-timezones 
UTC

ということでtzdataをいれて以下のようにして、解決しました。

- name: Add Timezone
  apt:
    name: "{{ item.name }}"
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - { name: tzdata }
  ignore_errors: aptget_ignore_errors

- name: Set timezone to Asia/Tokyo
  timezone:
    name: Asia/Tokyo
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0