How to run a cron job using Ansible Playbook

0 votes

Hi Guys,
I have configured Ansible. I want to run a Cron Job in the remote system using Ansible Playbook? How can I do that?

Sep 29, 2020 in Ansible by akhtar
• 38,230 points
9,639 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use a module named Cron in your Ansible Playbook. It can schedule your job according to your requirement as shown below.

- name: Cron Job
  hosts: webservers
  become: true
  tasks:
    - name: Crontab file exists
      cron:
        name: Add date and time to a file.
        minute: "*/2"
        hour: 9-16
        weekday: 1-5
        user: devops
        job: df >> /home/devops/disk_usage
        cron_file: disk_usage
        state: present
answered Sep 29, 2020 by MD
• 95,440 points

Related Questions In Ansible

0 votes
1 answer

How to pull a docker image using Ansible playbook?

Did you try using this? https://docs.ansible.com/ansible/latest/colle ...READ MORE

answered Nov 5, 2020 in Ansible by undermink
9,952 views
0 votes
1 answer

How to create a key pair on AWS using Ansible-Playbook?

Hi@akhtar, You can find the ec2_key module in ...READ MORE

answered Aug 12, 2020 in Ansible by MD
• 95,440 points
1,121 views
0 votes
1 answer

How to create a security group in AWS using Ansible-Playbook?

Hi@akhtar, You can use the ec2_group module in ...READ MORE

answered Aug 13, 2020 in Ansible by MD
• 95,440 points
3,380 views
0 votes
2 answers

How to create a directory in remote nodes using Ansible-Playbook?

You can read install and setup apache ...READ MORE

answered Aug 23, 2020 in Ansible by anonymous
• 160 points
3,564 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,460 views
+2 votes
1 answer
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,440 points
13,139 views
0 votes
1 answer

How to create a docker container using Ansible playbook?

Hi@akhtar, You can use the docker_container module in ...READ MORE

answered Aug 8, 2020 in Ansible by MD
• 95,440 points
4,035 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP