调整Ansible中的单用户的crontab mailto
我目前正在编辑类似特定用户的crontab条目:
---
- name: Create example cron entry
cron:
name: "Examplecrontab entry"
minute: "5"
hour: "5"
day: "5"
user: exampleuser
job: "examplejob"
state: present
这将在用户的crontab(crontab -l </code>)中创建以下条目:
#Ansible: Example cron entry
5 5 5 * * examplejob
我想添加mailto =“” 到本用户的crontab的顶部。结果应该如下:
MAILTO=""
#Ansible: Example cron entry
5 5 5 * * examplejob
我尝试将其添加到我的Ansible Play:
---
- name: Disable cron mailing to root
cronvar:
name: MAILTO
value: "\"\""
这是没有错误的情况下运行的,但并未如上所述创建预期的结果。
我已经从另一个 ,但这仅在创建/etc/cron.d
文件时起作用,而我的作业没有。
我如何通过我的原始游戏获得预期的结果?
从技术上讲,我可以使用lineInfile
模块,然后手动编辑/var/spool/cron/exampleser
文件,通过添加mailto =“”
最重要的是,但据我所知,这被认为是不良的实践,也不是合理的解决方案。
提前致谢。
I'm currently editing the crontab entry of a specific user like this:
---
- name: Create example cron entry
cron:
name: "Examplecrontab entry"
minute: "5"
hour: "5"
day: "5"
user: exampleuser
job: "examplejob"
state: present
This creates the following entry in my user's crontab (crontab -l
):
#Ansible: Example cron entry
5 5 5 * * examplejob
I want to add MAILTO=""
to the top of this user's crontab. The results should be as follows:
MAILTO=""
#Ansible: Example cron entry
5 5 5 * * examplejob
I've tried adding this to my ansible play:
---
- name: Disable cron mailing to root
cronvar:
name: MAILTO
value: "\"\""
This runs without error but doesn't create the expected result as mentioned above.
I've copied this from another post, but this only works when creating a /etc/cron.d
file, which my job does not do.
How can I get the expected result with my original play?
Technically I could use the lineinfile
module and manually edit the /var/spool/cron/exampleuser
file by adding MAILTO=""
manually to the top of it, but as far as I know that's considered bad practice and is not a legitimate solution.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来我没有正确阅读文档。查看默认为root,我添加了我的特定用户,并且问题已解决。对于其他任何人来说,我的剧本现在看起来像这样:
做
crontab -l </code>,因为示例使用者现在给了我这一点:
It seems I've failed to read the docs properly. Seeing the user property, which defaults to root, I've added my specific user and my issue has been fixed. For anyone else, my play looks like this now:
doing
crontab -l
as the exampleuser now gives me this:您可以指定
cron_file
指令在不同的cron文件中设置不同的mailto
。You can specify the
cron_file
directive to set a differentMAILTO
in different cron files.我认为您正在寻找的是
eg:
I think what you're looking for is cronvar_module
E.G.: