ansible常用模块之 -- cronvar模块 – 在crontabs中管理变量

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值