如果Ansible中参数的条件

问题描述 投票:0回答:1

这是将cronjob添加到crontab的任务:

    - name: Add job triggering logs rotation for clusters.
      cron:
        cron_file: '/etc/crontab'
        user: 'root'
        name: 'logrotate'
        minute: *
        hour: '*/4'
        job: '/etc/cron.daily/logrotate'
        state: present

我想完成的是,如果minute: */5中的hour: *devinventory_hostname,否则是minute: 0hour: */4

有没有办法在分钟和小时参数中添加条件?我可以使用模板来处理这个问题,而只是在提到的任务中添加这两个参数?

if-statement ansible conditional-statements logrotate
1个回答
0
投票

这是使用ternary过滤器实现此目标的一种方法:

ternary
© www.soinside.com 2019 - 2024. All rights reserved.