- name: Include distribution specific variables include_vars: "{{ lookup('first_found', search) }}" vars: search: files: - '{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version }}.yml' - '{{ ansible_distribution | lower }}.yml' - '{{ ansible_os_family | lower }}.yml' - '{{ ansible_system | lower }}.yml' - default.yml paths: - vars - name: install cron package package: name: '{{ cron_pkg }}' when: cron_pkg | default(false, true) is truthy register: cron_package_installed until: cron_package_installed is success - when: faketime_pkg | default(false, true) is truthy block: - name: install faketime packages package: name: '{{ faketime_pkg }}' register: faketime_package_installed until: faketime_package_installed is success when: ansible_distribution != 'Alpine' - name: install faketime packages - Alpine command: apk add -U {{ faketime_pkg }} when: ansible_distribution == 'Alpine' - name: Find libfaketime path shell: '{{ list_pkg_files }} {{ faketime_pkg }} | grep -F libfaketime.so.1' register: libfaketime_path_output when: list_pkg_files is defined - name: Set libfaketime path to default value set_fact: libfaketime_path: '/usr/lib/faketime/libfaketime.so.1' - name: Set libfaketime path - Alpine set_fact: libfaketime_path: '/{{ libfaketime_path_output.stdout_lines[0].strip() }}' when: ansible_distribution == 'Alpine' - name: Set libfaketime path - Other distributions set_fact: libfaketime_path: '{{ libfaketime_path_output.stdout_lines[0].strip() }}' when: ansible_distribution != 'Alpine' - when: ansible_service_mgr == 'systemd' block: - name: create directory for cron drop-in file file: path: '/etc/systemd/system/{{ cron_service }}.service.d' state: directory owner: root group: root mode: 0755 - name: Use faketime with cron service copy: content: |- [Service] Environment=LD_PRELOAD={{ libfaketime_path }} Environment="FAKETIME=+0y x10" Environment=RANDOM_DELAY=0 dest: '/etc/systemd/system/{{ cron_service }}.service.d/faketime.conf' owner: root group: root mode: 0644 - when: ansible_system == 'FreeBSD' name: Use faketime with cron service copy: content: |- cron_env='LD_PRELOAD={{ libfaketime_path }} FAKETIME="+0y x10"' dest: '/etc/rc.conf.d/cron' owner: root group: wheel mode: 0644 - name: enable cron service service: daemon-reload: "{{ (ansible_service_mgr == 'systemd') | ternary(true, omit) }}" name: '{{ cron_service }}' state: restarted when: ansible_distribution != 'Alpine' # Run busybox crond in the foreground: self-daemonizing closes all inherited fds, # including the one libfaketime (>= 0.9.13) holds for its flock-based stat lock, so # the next faked fstat() fails with EBADF and libfaketime aborts crond before it # schedules anything. - name: enable cron service - Alpine shell: crond -f & environment: FAKETIME: "+0y x10" LD_PRELOAD: "{{ libfaketime_path }}" when: ansible_distribution == 'Alpine' - name: See if /etc/pam.d/crond exists stat: path: /etc/pam.d/crond register: pamd # https://github.com/lxc/lxc/issues/661#issuecomment-222444916 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=726661 - name: Work around containers not being able to write to /proc/self/loginuid command: sed -i '/pam_loginuid\.so$/ s/required/optional/' /etc/pam.d/crond when: - pamd.stat.exists