Ansible cron 作业不适用于两个任务

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

下面是main.yml

---
# your_playbook.yml
- hosts: all
  become: yes
  gather_facts: no
  become_method: sudo
  roles:
    - include_role:
      name: cron_job
      vars:
        cron_jobs:
          - script_path: "/export/storage_mount.sh"
            script_arguments: "action"
          - script_path: "/export/service_status.sh"
            script_arguments: ""

cron 角色:

---
- name: Create cron job
  ansible.builtin.cron:
    name: "Run script every 5 minutes"
    minute: "5"
    job: "/bin/bash {{ item.script_path }} {{ item.script_arguments }}"
    state: present
  loop: "{{ cron_jobs }}"

角色运行输出:

changed: [host01] => (item={'script_path': '/export/apps/scripts/storage_mount.sh', 'script_arguments': 'action'})
changed: [host01] => (item={'script_path': '/export/apps/scripts/service_status.sh', 'script_arguments': ''})

它只在 crontab 中创建一个条目而不是两个条目

#Ansible: Run script every 5 minutes
5 * * * * /bin/bash /export/service_status.sh 

如何解决这个问题

ansible devops
1个回答
0
投票

如何在 Ansible

cron
模块上循环?

这可能是因为您使用了相同的参数

name: "Run script every 5 minutes"

你可以

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