Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timezone cannot change timezone in systemd based containers #19280

Closed
tmshn opened this Issue Dec 13, 2016 · 8 comments

Comments

Projects
None yet
4 participants
@tmshn
Copy link
Contributor

tmshn commented Dec 13, 2016

From @kayhayen on December 3, 2016 8:49

In my playbook, I got the following:

  - name: Set timezone to CEST.
    timezone:
        name: Europe/Berlin
    when: "'{{ansible_virtualization_role}}' != 'guest'"

The condition was added as a workaround, because in the Debian Stretch, systemd based LXC container, timedatectl reports:

Failed to create bus connection: No such file or directory

This is likely because systemd-timesyncd and systemd-timedated are disabled in virtual machines, but Ansible insists on using them to change the timezone.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • timezone
ANSIBLE VERSION
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION
  - name: Set timezone to CEST.
    timezone:
        name: Europe/Berlin
OS / ENVIRONMENT

Running on Debian Testing, managing Debian Testing container running under LXC on Turris Omnia, OpenWRT kernel.

SUMMARY

Changing the timezone is definitely possible without timedatectl. It could also be that Debian falsely disables systemd-timedated inside the container when there is virtualization, of that I am not entirely sure.

STEPS TO REPRODUCE

Use example above on LXC Debian Stretch container.

EXPECTED RESULTS

Expected to change /etc/timezone

ACTUAL RESULTS

Crashed ansible playbook.

Copied from original issue: ansible/ansible-modules-extras#3641

@tmshn

This comment has been minimized.

Copy link
Contributor Author

tmshn commented Dec 13, 2016

From @ansibot on December 4, 2016 14:21

@tmshn ping, this issue is waiting for your response.
click here for bot help

@tmshn

This comment has been minimized.

Copy link
Contributor Author

tmshn commented Dec 13, 2016

From @ansibot on December 7, 2016 15:50

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

@tmshn

This comment has been minimized.

Copy link
Contributor Author

tmshn commented Dec 13, 2016

@kayhayen So the situation is: with LXC container,

  • Debian virtual machine has timedatectl command
  • but the command doesn't work,

right?

Then, could you tell me

  1. What will happen if you simply run timedatectl in the container (stdout, stderr and exit code)? Display "Failed to create bus connection: No such file or directory" and exit with 2?
  2. Does the module works with the following patch (just force to use NosystemdTimezone rather than SystemdTimezone)?
diff --git a/lib/ansible/modules/system/timezone.py b/lib/ansible/modules/system/timezone.py
index 7d8d9ae..057becb 100644
--- a/lib/ansible/modules/system/timezone.py
+++ b/lib/ansible/modules/system/timezone.py
@@ -98,10 +98,11 @@ class Timezone(object):
             module: The AnsibleModule.
         """
         if get_platform() == 'Linux':
-            if module.get_bin_path('timedatectl') is not None:
-                return super(Timezone, SystemdTimezone).__new__(SystemdTimezone)
-            else:
-                return super(Timezone, NosystemdTimezone).__new__(NosystemdTimezone)
+            # if module.get_bin_path('timedatectl') is not None:
+            #     return super(Timezone, SystemdTimezone).__new__(SystemdTimezone)
+            # else:
+            #     return super(Timezone, NosystemdTimezone).__new__(NosystemdTimezone)
+            return super(Timezone, NosystemdTimezone).__new__(NosystemdTimezone)
         else:
             # Not supported yet
             return super(Timezone, Timezone).__new__(Timezone)
@kayhayen

This comment has been minimized.

Copy link

kayhayen commented Dec 15, 2016

Hello,

yes indeed this is the error and yes, your patch works. I switched timezone with dpkg-reconfigure tzdata, and with the patch, this works.

Yours,
Kay

@tmshn

This comment has been minimized.

Copy link
Contributor Author

tmshn commented Dec 15, 2016

@kayhayen Okay, situation understood. I hope this pr -> #19367 will fix the issue, could you also try this out?

@kayhayen

This comment has been minimized.

Copy link

kayhayen commented Dec 17, 2016

I think it does. I tried it, but I noticed that the real issue was that "dbus" was not installed. So not the disabled daemon (it is), but it being unreachable was the issue. Once dbus daemon is there, the "timedatectl" starts to work and does the job, even with ansible unmodified.

So this is a robustness feature and not generally applicable to all kinds of containers. My LXC container may or may not be typical. It's my first one. I had used ansible previously only on proper virtual machines that are full installs.

Yours,
Kay

@tmshn

This comment has been minimized.

Copy link
Contributor Author

tmshn commented Dec 19, 2016

Got it 👍
Anyway the PR would be useful, so I mark it as ready to merge.

Thanks for useful report, @kayhayen !

@abeluck

This comment has been minimized.

Copy link

abeluck commented Jan 14, 2019

Is it necessary to have the warning?

 [WARNING]: timedatectl command was found but not usable: Failed to create bus
connection: No such file or directory . using other method.

In my opinion, it is unnecessary and creates extra critical output when in fact the timezone was changed successfully. Do users of this module really care what the underlying implementation is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.