Bug 2052048 - Repeated Ansible Role run scheduling adds extra time to specified start date
Summary: Repeated Ansible Role run scheduling adds extra time to specified start date
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Ansible - Configuration Management
Version: 6.11.0
Hardware: Unspecified
OS: Linux
unspecified
high
Target Milestone: 6.11.0
Assignee: Adam Ruzicka
QA Contact: Danny Synk
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-02-08 15:19 UTC by Danny Synk
Modified: 2022-07-05 14:33 UTC (History)
5 users (show)

Fixed In Version: tfm-rubygem-foreman_remote_execution-5.0.6, tfm-rubygem-foreman-tasks-5.2.3
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-07-05 14:32:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 34691 0 Normal Closed Repeated Ansible run scheduling adds extra time to specified start date 2022-04-06 10:51:08 UTC
Foreman Issue Tracker 34741 0 Normal Closed CronParser misbehaves if the cronline and reference time are in different timezones 2022-04-06 10:53:32 UTC
Foreman Issue Tracker 34742 0 Normal Closed Timezone information is discarded when triggering a job through API 2022-04-06 10:53:34 UTC
Red Hat Product Errata RHSA-2022:5498 0 None None None 2022-07-05 14:33:06 UTC

Description Danny Synk 2022-02-08 15:19:56 UTC
Description of problem:
When scheduling repeated Ansible Role runs on either a single host or a host group, the initial run is scheduled after the start date specified when creating the job.

Version-Release number of selected component (if applicable):
Satellite 7.0.0, snap 7, running on both RHEL 7 and RHEL 8

How reproducible:
100%

Steps to Reproduce:
1. Register a host to Satellite.
2. Import Ansible Roles to Satellite.
3. Assign an Ansible Role to the host.
4. Navigate to Hosts > All Hosts > [hostname], click the `New UI` button, then select the `Ansible` tab and the `Jobs` subtab.
5. Click the `Schedule recurring job` button.
6. Schedule an hourly job with a start time of 12:00 and a start date of tomorrow.
7. Note the start time of the next run by hovering the mouse pointer over the value in the `Next Run` column.
8. Cancel the scheduled job.
9. Repeat steps 6-8 with daily, weekly, and monthly repetition schedules.

Actual results:
- Hourly jobs have their first run scheduled for ten hours after the specified start time.
- Daily jobs have their first run scheduled for 24 hours after the specified start time.
- Weekly jobs have their first run scheduled for one week after the specified start time.
- Monthly jobs have their first run scheduled for one month after the specified start time. This appears to be an increment of calendar months and not a specific number of days, i.e. a job scheduled to being on 11 February will have its first run scheduled for 11 March.


Expected results:
The start date and time of the first run match the values entered when the job is created.


Additional info:
- This behavior is identical when scheduling a repeated Ansible Roles run against a host group.
- This behavior was tested with the `Default timezone` setting in the default state (empty).
- Entering today's date as the start date for a repeated run displays the error message `Must not be in the past`, even in the specified start time is 12 hours after the current time. I am uncertain if I should create a separate BZ for this behavior or if it is related to the behavior reported above.

Comment 2 Ondřej Ezr 2022-03-28 20:52:05 UTC
Created redmine issue https://projects.theforeman.org/issues/34691 from this bug

Comment 6 Leos Stejskal 2022-04-05 05:42:48 UTC
Hi,
I've been successful in reproducing the issue on my local development setup (latest develop),
sadly I still didn't find the way how to fix it, here are my observations so far:

UC1: Foreman and the user both in "Europe/Prague (CEST, +0200)" zone

* Set recurring job: 00:30, monthly, 30.04.2022

When you submit the form, parameters sent are `"scheduling"=>{"startAt"=>"2022-04-29T22:30:00.000Z"}`
and job is planned correctly.


UC2: Foreman and user in "America/Toronto (EDT, -0400)" zone
* Set recurring job: 00:30, monthly, 30.04.2022

When you submit the form, parameters sent are `"scheduling"=>{"startAt"=>"2022-04-06T04:30:00.000Z"}`
For some reason frontend code is changing the date to 06.04.2022, not sure why.

I will continue in the investigation and share my progress when I'll have more information.
Also want to note that this issue is not for recurring jobs in remote executions, it's just for Ansible plugin

Comment 7 Leos Stejskal 2022-04-05 13:25:40 UTC
I did some more testing and I was able to reproduce the issue
with creating job invocation with recurring logic 
from the job invocation form, so I believe that the issue 
is in the foreman-tasks plugin rather than in the foreman-ansible.

**Steps to reproduce the issue:**
- Set your dev environment timezone to "EDT -0400", for example "America/Kentucky/Monticello (EDT, -0400)"
- (user should get the time zone from the browser)
- Create job with following parameters:
  Search Query: "name ~ *"
  command: "date"
  Schedule: "Set up recurring execution"
  Repeats: "monthly"
  Days: "30"
  At: "00:30"
  Starts at: "2022-04-30 00:30"
  
The scheduled start date is "2022-05-30 00:30:00 -0400", one month later, which is wrong.

If you set the time zone to "Europe/Prague (CEST, +0200)", 
the scheduled start date is correctly "2022-04-30 00:30:00 +0200".

---

@aruzicka Could you please take a look? I may be wrong and 
the issue is somewhere else but this is all I've got so far.

Comment 8 Adam Ruzicka 2022-04-06 08:25:44 UTC
Fixes will land in foreman-tasks and foreman_remote_execution. Leaving the component set to ansible as the new ansible workflow makes it rather easy to trigger the bug.

Comment 9 Adam Ruzicka 2022-04-06 10:55:01 UTC
Fixes were merged in upstream, setting fixed-in-release, upstream releases will go out end of week-ish

Comment 10 Adam Ruzicka 2022-04-21 14:30:37 UTC
Releases with fixes just went out.

Comment 11 Danny Synk 2022-04-27 20:20:10 UTC
Verified on Satellite 6.11, snap 18 running on both RHEL 7 and RHEL 8.

Steps to Test:
1. Register a host to Satellite.
2. Import Ansible Roles to Satellite.
3. Assign an Ansible Role to the host.
4. Navigate to Hosts > All Hosts > [hostname], select the `Ansible` tab, then select the the `Jobs` subtab.
5. Click the `Schedule recurring job` button.
6. Schedule an hourly job with a start time of 12:00 and a start date of tomorrow.
7. Note the start time of the next run by hovering the mouse pointer over the value in the `Next Run` column.
8. Cancel the scheduled job.
9. Repeat steps 6-8 with daily, weekly, and monthly repetition schedules.

Expected Results:
The start date and time of the first run match the values entered when the job is created.

Actual Results:
The start date and time of the first run match the values entered when the job is created.

Comment 14 errata-xmlrpc 2022-07-05 14:32:53 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.11 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:5498


Note You need to log in before you can comment on or make changes to this bug.