Debian Codegraph @

test/integration/targets/setup_cron/tasks/main.yml

raw
1 - name: Include distribution specific variables
2 include_vars: "{{ lookup('first_found', search) }}"
3 vars:
4 search:
5 files:
6 - '{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version }}.yml'
7 - '{{ ansible_distribution | lower }}.yml'
8 - '{{ ansible_os_family | lower }}.yml'
9 - '{{ ansible_system | lower }}.yml'
10 - default.yml
11 paths:
12 - vars
13
14 - name: install cron package
15 package:
16 name: '{{ cron_pkg }}'
17 when: cron_pkg | default(false, true) is truthy
18 register: cron_package_installed
19 until: cron_package_installed is success
20
21 - when: faketime_pkg | default(false, true) is truthy
22 block:
23 - name: install faketime packages
24 package:
25 name: '{{ faketime_pkg }}'
26 register: faketime_package_installed
27 until: faketime_package_installed is success
28 when: ansible_distribution != 'Alpine'
29
30 - name: install faketime packages - Alpine
31 command: apk add -U {{ faketime_pkg }}
32 when: ansible_distribution == 'Alpine'
33
34 - name: Find libfaketime path
35 shell: '{{ list_pkg_files }} {{ faketime_pkg }} | grep -F libfaketime.so.1'
36 register: libfaketime_path_output
37 when: list_pkg_files is defined
38
39 - name: Set libfaketime path to default value
40 set_fact:
41 libfaketime_path: '/usr/lib/faketime/libfaketime.so.1'
42
43 - name: Set libfaketime path - Alpine
44 set_fact:
45 libfaketime_path: '/{{ libfaketime_path_output.stdout_lines[0].strip() }}'
46 when: ansible_distribution == 'Alpine'
47
48 - name: Set libfaketime path - Other distributions
49 set_fact:
50 libfaketime_path: '{{ libfaketime_path_output.stdout_lines[0].strip() }}'
51 when: ansible_distribution != 'Alpine'
52
53
54 - when: ansible_service_mgr == 'systemd'
55 block:
56 - name: create directory for cron drop-in file
57 file:
58 path: '/etc/systemd/system/{{ cron_service }}.service.d'
59 state: directory
60 owner: root
61 group: root
62 mode: 0755
63
64 - name: Use faketime with cron service
65 copy:
66 content: |-
67 [Service]
68 Environment=LD_PRELOAD={{ libfaketime_path }}
69 Environment="FAKETIME=+0y x10"
70 Environment=RANDOM_DELAY=0
71 dest: '/etc/systemd/system/{{ cron_service }}.service.d/faketime.conf'
72 owner: root
73 group: root
74 mode: 0644
75
76 - when: ansible_system == 'FreeBSD'
77 name: Use faketime with cron service
78 copy:
79 content: |-
80 cron_env='LD_PRELOAD={{ libfaketime_path }} FAKETIME="+0y x10"'
81 dest: '/etc/rc.conf.d/cron'
82 owner: root
83 group: wheel
84 mode: 0644
85
86 - name: enable cron service
87 service:
88 daemon-reload: "{{ (ansible_service_mgr == 'systemd') | ternary(true, omit) }}"
89 name: '{{ cron_service }}'
90 state: restarted
91 when: ansible_distribution != 'Alpine'
92
93 # Run busybox crond in the foreground: self-daemonizing closes all inherited fds,
94 # including the one libfaketime (>= 0.9.13) holds for its flock-based stat lock, so
95 # the next faked fstat() fails with EBADF and libfaketime aborts crond before it
96 # schedules anything.
97 - name: enable cron service - Alpine
98 shell: crond -f &
99 environment:
100 FAKETIME: "+0y x10"
101 LD_PRELOAD: "{{ libfaketime_path }}"
102 when: ansible_distribution == 'Alpine'
103
104 - name: See if /etc/pam.d/crond exists
105 stat:
106 path: /etc/pam.d/crond
107 register: pamd
108
109 # https://github.com/lxc/lxc/issues/661#issuecomment-222444916
110 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=726661
111 - name: Work around containers not being able to write to /proc/self/loginuid
112 command: sed -i '/pam_loginuid\.so$/ s/required/optional/' /etc/pam.d/crond
113 when:
114 - pamd.stat.exists