ansible-role-snapraid icon indicating copy to clipboard operation
ansible-role-snapraid copied to clipboard

Where gets the snapraid-runner cron job actually defined?

Open lowrents opened this issue 2 years ago • 0 comments

Hi,

hopefully this is not too obvious because to be hones I am investigating this a couple of hours now...

I am actually trying to understand how the setup cron job snapraid-runner-task defines the cron job, which gets created in snapraid-runner.yml.

Define snapraid_runner_cron_jobs in defaults > main.yml

snapraid_runner_cron_jobs:
  #- { job: '{{ snapraid_runner_command }}', name: 'snapraid_runner', weekday: '*', hour: '01' }
  - { job: 'test', name: 'snapraid_runner', weekday: '*', hour: '01' }

Create cronjob in tasks > snapraid-runner.yml with item snapraid_runner_cron_jobs

- name: setup cron job snapraid-runner
  cron:
    user: "root"
    job: "{{ item.job }}"
    name: "{{ item.name }}"
    weekday: "{{ item.weekday | default ('*') }}"
    minute: "{{ item.minute | default ('00')}}"
    hour: "{{ item.hour | default ('00') }}"
    dom: "{{ item.dom|default('*') }}"
  with_items:
    - "{{ snapraid_runner_cron_jobs }}"

But when I have a look in my crontab sudo cat cd /var/spool/cron/crontabs/root gives me:

#Ansible: snapraid_runner
00 3 * * 0 docker stop $(docker ps -q); rsync -avz --delete --exclude cache /opt/docker/data /mnt/storage/docker_data; docker start $(docker ps -a -q) && python3 /opt/snapraid-runner/snapraid-runner.py -c /opt/snapraid-runner/snapraid-runner.conf

When I modify the Playbook to debug the snapraid_runner_cron_jobs and snapraid_runner_command variable in the tasks > main.yml at the very top by:

- name: Debug snapraid_runner_cron_jobs
  debug:
   msg: "{{ snapraid_runner_cron_jobs }}"
- name: Debug snapraid_runner_command
  debug:
   msg: "{{ snapraid_runner_command }}"

Running this Playbook gives me

TASK [ironicbadger.snapraid : Debug snapraid_runner_cron_jobs] ******************************************
ok: [nas] => {
    "msg": [
        {
            "hour": "3",
            "job": "docker stop $(docker ps -q); rsync -avz --delete --exclude cache /opt/docker/data /mnt/storage/docker_data; docker start $(docker ps -a -q) && python3 /opt/snapraid-runner/snapraid-runner.py -c /opt/snapraid-runner/snapraid-runner.conf ",
            "name": "snapraid_runner",
            "weekday": "0"
        }
    ]
}

TASK [ironicbadger.snapraid : Debug snapraid_runner_command] ********************************************
ok: [nas] => {
    "msg": "python3 /opt/snapraid-runner/snapraid-runner.py -c /opt/snapraid-runner/snapraid-runner.conf"
}

Where is this first docker part coming from? As far as I understand, roles in particular cannot have "hidden default variables" regarding the documentation.

As I tested, refine the snapraid_runner_command affects the cron job, either by define the variable in defaults > main.yml or by using set_fact in tasks > main.yml.

Actually this is my very first Ansible project and I had a couple of time similar situation where I missed something obvious, but this one drives me crazy because I cannot solve it.

Appreciate any Ideas. Thanks!

lowrents avatar Jun 19 '22 08:06 lowrents