lowlydba / lowlydba.sqlserver

:spoon: A cross-platform Ansible collection using PowerShell to configure and maintain SQL Server.
https://galaxy.ansible.com/ui/repo/published/lowlydba/sqlserver
GNU General Public License v3.0
22 stars 12 forks source link

[Bug] agent_job_schedule does not change when set to enabled: true #272

Open da-access-group opened 3 weeks ago

da-access-group commented 3 weeks ago

Describe the bug I've recently deploy an agent_job_schedule without the enabled property, by default this appears to create a schedule that isn't enabled. I have since updated my Ansible configuration to add "enabled: true" to the agent_job_schedule task but this does not cause the schedule to be changed.

To Reproduce Create an agent_job and agent_job_schedule

    - name: Create a job 
      lowlydba.sqlserver.agent_job:
        sql_instance: [REDACTED]
        job: MyJob
        force: true

    - name: Create a job schedule
      lowlydba.sqlserver.agent_job_schedule:
        sql_instance: [REDACTED]
        schedule: DailySchedule
        force: true
        start_date: '20200525'
        end_date: '20990525'
        start_time: '010500'
        end_time: '140030'
        state: present
        job: 'MyJob'

Modify the agent_job_schedule to add the enabled property and set this to true

    - name: Create a job schedule
      lowlydba.sqlserver.agent_job_schedule:
        sql_instance: [REDACTED]
        schedule: DailySchedule
        force: true
        enabled: true
        start_date: '20200525'
        end_date: '20990525'
        start_time: '010500'
        end_time: '140030'
        state: present
        job: 'MyJob'

Ansible returns with no changes:

{
  "changed": false,
  "invocation": {
    "module_args": {
      "end_time": "140030",
      "sql_instance": "[REDACTED]",
      "frequency_relative_interval": null,
      "frequency_subday_interval": null,
      "frequency_subday_type": null,
      "start_date": "20200525",
      "frequency_type": null,
      "state": "present",
      "frequency_interval": null,
      "job": "MyJob",
      "start_time": "010500",
      "sql_username": null,
      "sql_password": null,
      "schedule": "DailySchedule",
      "enabled": true,
      "force": true,
      "frequency_recurrence_factor": null,
      "end_date": "20990525"
    }
  },
  "data": {
    "ComputerName": "[REDACTED]",
    "InstanceName": "MSSQLSERVER",
    "SqlInstance": "[REDACTED]",
    "Description": "Occurs on 5/25/2020 at 1:05:00 AMat 1:05:00 AM. Schedule will used between 5/25/2020 and 5/25/2099.",
    "ScheduleName": "DailySchedule",
    "ScheduleUid": "29214802-8617-432f-acca-5064c67cb5a4",
    "ActiveEndDate": "2099-05-25T00:00:00.0000000",
    "ActiveEndTimeOfDay": {
      "Ticks": 504300000000,
      "Days": 0,
      "Hours": 14,
      "Milliseconds": 0,
      "Minutes": 0,
      "Seconds": 30,
      "TotalDays": 0.5836805555555555,
      "TotalHours": 14.008333333333333,
      "TotalMilliseconds": 50430000,
      "TotalMinutes": 840.5,
      "TotalSeconds": 50430
    },
    "ActiveStartDate": "2020-05-25T00:00:00.0000000",
    "ActiveStartTimeOfDay": {
      "Ticks": 39000000000,
      "Days": 0,
      "Hours": 1,
      "Milliseconds": 0,
      "Minutes": 5,
      "Seconds": 0,
      "TotalDays": 0.04513888888888889,
      "TotalHours": 1.0833333333333333,
      "TotalMilliseconds": 3900000,
      "TotalMinutes": 65,
      "TotalSeconds": 3900
    },
    "DateCreated": "2024-10-31T10:15:41.4530000",
    "FrequencyInterval": 0,
    "FrequencyRecurrenceFactor": 0,
    "FrequencyRelativeIntervals": "0",
    "FrequencySubDayInterval": 0,
    "FrequencySubDayTypes": "Unknown",
    "FrequencyTypes": "OneTime",
    "IsEnabled": false,
    "JobCount": 1
  },
  "_ansible_no_log": false
}

Expected behavior I would expect Ansible to modify the schedule so it is now enabled.

Versions(please complete the following information):

lowlydba commented 2 weeks ago

Hi! Thanks for the bug report. I don't have a ton of time right now to dedicate to this project, but bug fix PRs are welcome!