1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cronvar: ensure creation of /etc/cron.d in test (#4440) (#4444)

* ensure creation of /etc/cron.d in test

* fixed typo

(cherry picked from commit 9e0ff8ba4b)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-04-03 10:54:44 +02:00 committed by GitHub
parent e89648a114
commit 47aa93d970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,115 +3,117 @@
# and should not be used as examples of how to write Ansible roles # # and should not be used as examples of how to write Ansible roles #
#################################################################### ####################################################################
- when: - name: Ensure /etc/cron.d directory exists
- not (ansible_os_family == 'Alpine' and ansible_distribution_version is version('3.15', '<')) # TODO file:
block: path: /etc/cron.d
- name: Create EMAIL cron var state: directory
cronvar:
name: EMAIL
value: doug@ansibmod.con.com
register: create_cronvar1
- name: Create EMAIL cron var again - name: Create EMAIL cron var
cronvar: cronvar:
name: EMAIL name: EMAIL
value: doug@ansibmod.con.com value: doug@ansibmod.con.com
register: create_cronvar2 register: create_cronvar1
- name: Check cron var value - name: Create EMAIL cron var again
shell: crontab -l -u root | grep -c EMAIL=doug@ansibmod.con.com cronvar:
register: varcheck1 name: EMAIL
value: doug@ansibmod.con.com
register: create_cronvar2
- name: Modify EMAIL cron var - name: Check cron var value
cronvar: shell: crontab -l -u root | grep -c EMAIL=doug@ansibmod.con.com
name: EMAIL register: varcheck1
value: jane@ansibmod.con.com
register: create_cronvar3
- name: Check cron var value again - name: Modify EMAIL cron var
shell: crontab -l -u root | grep -c EMAIL=jane@ansibmod.con.com cronvar:
register: varcheck2 name: EMAIL
value: jane@ansibmod.con.com
register: create_cronvar3
- name: Remove EMAIL cron var - name: Check cron var value again
cronvar: shell: crontab -l -u root | grep -c EMAIL=jane@ansibmod.con.com
name: EMAIL register: varcheck2
state: absent
register: remove_cronvar1
- name: Remove EMAIL cron var again - name: Remove EMAIL cron var
cronvar: cronvar:
name: EMAIL name: EMAIL
state: absent state: absent
register: remove_cronvar2 register: remove_cronvar1
- name: Check cron var value again - name: Remove EMAIL cron var again
shell: crontab -l -u root | grep -c EMAIL cronvar:
register: varcheck3 name: EMAIL
failed_when: varcheck3.rc == 0 state: absent
register: remove_cronvar2
- name: Add cron var to custom file - name: Check cron var value again
cronvar: shell: crontab -l -u root | grep -c EMAIL
name: TESTVAR register: varcheck3
value: somevalue failed_when: varcheck3.rc == 0
cron_file: cronvar_test
register: custom_cronfile1
- name: Add cron var to custom file again - name: Add cron var to custom file
cronvar: cronvar:
name: TESTVAR name: TESTVAR
value: somevalue value: somevalue
cron_file: cronvar_test cron_file: cronvar_test
register: custom_cronfile2 register: custom_cronfile1
- name: Check cron var value in custom file - name: Add cron var to custom file again
command: grep -c TESTVAR=somevalue {{ cron_config_path }}/cronvar_test cronvar:
register: custom_varcheck1 name: TESTVAR
value: somevalue
cron_file: cronvar_test
register: custom_cronfile2
- name: Change cron var in custom file - name: Check cron var value in custom file
cronvar: command: grep -c TESTVAR=somevalue {{ cron_config_path }}/cronvar_test
name: TESTVAR register: custom_varcheck1
value: newvalue
cron_file: cronvar_test
register: custom_cronfile3
- name: Check cron var value in custom file - name: Change cron var in custom file
command: grep -c TESTVAR=newvalue {{ cron_config_path }}/cronvar_test cronvar:
register: custom_varcheck2 name: TESTVAR
value: newvalue
cron_file: cronvar_test
register: custom_cronfile3
- name: Remove cron var from custom file - name: Check cron var value in custom file
cronvar: command: grep -c TESTVAR=newvalue {{ cron_config_path }}/cronvar_test
name: TESTVAR register: custom_varcheck2
value: newvalue
cron_file: cronvar_test
state: absent
register: custom_remove_cronvar1
- name: Remove cron var from custom file again - name: Remove cron var from custom file
cronvar: cronvar:
name: TESTVAR name: TESTVAR
value: newvalue value: newvalue
cron_file: cronvar_test cron_file: cronvar_test
state: absent state: absent
register: custom_remove_cronvar2 register: custom_remove_cronvar1
- name: Check cron var value - name: Remove cron var from custom file again
command: grep -c TESTVAR=newvalue {{ cron_config_path }}/cronvar_test cronvar:
register: custom_varcheck3 name: TESTVAR
failed_when: custom_varcheck3.rc == 0 value: newvalue
cron_file: cronvar_test
state: absent
register: custom_remove_cronvar2
- name: Esure cronvar tasks did the right thing - name: Check cron var value
assert: command: grep -c TESTVAR=newvalue {{ cron_config_path }}/cronvar_test
that: register: custom_varcheck3
- create_cronvar1 is changed failed_when: custom_varcheck3.rc == 0
- create_cronvar2 is not changed
- create_cronvar3 is changed - name: Ensure cronvar tasks did the right thing
- remove_cronvar1 is changed assert:
- remove_cronvar2 is not changed that:
- varcheck1.stdout == '1' - create_cronvar1 is changed
- varcheck2.stdout == '1' - create_cronvar2 is not changed
- varcheck3.stdout == '0' - create_cronvar3 is changed
- custom_remove_cronvar1 is changed - remove_cronvar1 is changed
- custom_remove_cronvar2 is not changed - remove_cronvar2 is not changed
- custom_varcheck1.stdout == '1' - varcheck1.stdout == '1'
- custom_varcheck2.stdout == '1' - varcheck2.stdout == '1'
- custom_varcheck3.stdout == '0' - varcheck3.stdout == '0'
- custom_remove_cronvar1 is changed
- custom_remove_cronvar2 is not changed
- custom_varcheck1.stdout == '1'
- custom_varcheck2.stdout == '1'
- custom_varcheck3.stdout == '0'