【发布时间】:2021-06-24 00:59:59
【问题描述】:
我尝试使用以下代码-
- name: "cron"
hosts: localhost
tasks:
- cron:
name: "Puppet agent"
job: "/bin/true"
state: present
disabled: True
它没有评论现有的 cron 作业,而是附加了 #Ansible: test.我想修改现有的 cron 作业,而不是追加。
cron 作业看起来像这样- crontab -l
# puppet Name: Puppet agent
* * * * * /bin/true
执行ansible代码后的结果是: crontab -l
# puppet Name: Puppet agent
* * * * * /bin/true
# Ansible: Puppet agent
#* * * * * /bin/true
【问题讨论】:
-
好吧,ansible 预计以前的剧本使用
cron:任务插入该条目,因此无法识别手动修改的 crontab 的部分。您需要使用...infile:任务之一来使该 crontab 合规,以便开始使用 ansible 对其进行管理 -
非常感谢您的回复。您能否详细解释一下 infile: 任务。我该如何使用它?
-
见docs.ansible.com/ansible/latest/collections/ansible/builtin/…(有lineinfile和blockinfile模块)