ansible常用模块之 — cronvar模块 – 在crontabs中管理变量
cronvar模块 – 在crontabs中管理变量
一、摘要
- 使用此模块管理crontab变量。
- 该模块允许您创建、更新或删除cron变量定义
二、参数
参数 | 选项/默认值 | 描述 |
---|---|---|
backup boolean |
· no ← · yes |
如果设置了,在修改crontab之前创建一个备份。该模块在备份变量中返回备份的位置 |
cron_file string |
如果指定,则使用此文件而不是单个用户的crontab。 如果没有前导/,则假定它在/etc/cron.d中 有了前导/,这被认为是绝对的。 |
|
insertafter string |
如果指定了,则该变量将插入到指定的变量之后。 使用state=present。 |
|
insertbefore string |
如果指定了,则该变量将插入到指定的变量之前。 使用state=present。 |
|
name string required |
crontab变量的名称。 | |
state string |
· present ← · absent |
是否确保该变量存在或不存在。 |
user string |
需要修改crontab的特定用户。 该参数在未设置时默认为root。 |
|
value string |
要将此变量设置为的值。如果需要state=present。 |
三、示例
# 确保存在“EMAIL=doug@ansibmod.con.com”这样的条目
- name: Ensure entry like "EMAIL=doug@ansibmod.con.com" exists
cronvar:
name: EMAIL
value: doug@ansibmod.con.com
# 确保变量不存在。这可能会删除任何名为"LEGACY"的变量
- name: Ensure a variable does not exist. This may remove any variable named "LEGACY"
cronvar:
name: LEGACY
state: absent
# 在/etc/cron.d下的文件中添加一个变量
- name: Add a variable to a file under /etc/cron.d
cronvar:
name: LOGFILE
value: /var/log/yum-autoupdate.log
user: root
cron_file: ansible_yum-autoupdate
官方文档:https://docs.ansible.com/ansible/2.9/modules/cronvar_module.html#cronvar-module