0

我创建了这个剧本来设置 crontab:

- name: Set PATH to crontab
  cron:
    name: PATH
    env: yes
    user: barman
    job: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/barman/.local/bin:/var/lib/barman/bin:/usr/pgsql-10/bin/

- name: Automatically run backup for App1
  cron:
    name: "Run Backup for App1"
    minute: "0"
    hour: "3"
    user: barman
    job: "barman cron && barman backup app1"

- name: Automatically run backup for App2
  cron:
    name: "Run Backup for App2"
    minute: "0"
    hour: "4"
    user: barman
    job: "barman cron && barman backup app2"

但我只在/etc/cron.d/barman文件下找到了这个:

# m h  dom mon dow   user     command
  * *    *   *   *   barman   [ -x /usr/bin/barman ] && /usr/bin/barman -q cron

似乎没有正确设置任务。

4

1 回答 1

0

问:“我只在 /etc/cron.d/barman 下找到了这个”

A:看看用户barman的crontab

shell> crontab -u barman -l

这取决于存储这些文件的操作系统。例如,Ubuntu 将文件存储在/var/spool/cron/crontabs/但 FreeBSD 使用/var/cron/tabs/. 请参阅参数cron_file

使用cronvar管理 crontabs 中的变量。例如

- name: Set PATH to crontab
  cronvar:
    name: PATH
    user: barman
    value: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/barman/.local/bin:/var/lib/barman/bin:/usr/pgsql-10/bin/

,或修复任务 cron Set PATH to crontab。引用参数env

“...名称和值参数是环境变量的名称和值。”

- name: Set PATH to crontab
  cron:
    name: PATH
    env: yes
    user: barman
    value: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/barman/.local/bin:/var/lib/barman/bin:/usr/pgsql-10/bin/
于 2020-03-10T11:11:03.593 回答