theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
https://theforeman.github.io/foreman-ansible-modules/
GNU General Public License v3.0
149 stars 166 forks source link

sync_plans role not idempotent #1804

Open myllynen opened 4 days ago

myllynen commented 4 days ago

This simple playbooks reports changed on every run (tested against Satellite 6.16):

---
- name: Configure Red Hat Satellite
  hosts: satellite
  become: true
  gather_facts: true
  vars:
    satellite_sync_plans:
      - name: Weekly Red Hat repository sync
        interval: weekly
        sync_date: 2022-01-01 02:02:00 UTC
        enabled: true
        products:
          - Red Hat Satellite Capsule
          - Red Hat Enterprise Linux for x86_64
  roles:
    - redhat.satellite.sync_plans

Since no passwords are involved here perhaps it would be possible to make this idempotent. Thanks.

evgeni commented 4 days ago

Can you post the --diff output? I bet it's the way the date is stored (iirc that recently changed)

myllynen commented 4 days ago

Here's the --diff output:

TASK [redhat.satellite.sync_plans : Create Sync Plans] ***************************************************************************************************************************************************************************************
Thursday 28 November 2024  17:17:33 +0200 (0:00:00.041)       0:00:00.041 ***** 
changed: [satellite.example.com] => (item={'name': 'Weekly Red Hat repository sync', 'interval': 'weekly', 'sync_date': '2022-01-01 02:02:00 UTC', 'enabled': True, 'products': ['Red Hat Satellite Capsule', 'Red Hat Enterprise Linux for x86_64']})

Here's also -v output just in case:

TASK [redhat.satellite.sync_plans : Create Sync Plans] ********************************************************************************************************************************************************************************[2/209]
Thursday 28 November 2024  17:18:26 +0200 (0:00:00.041)       0:00:00.041 *****                                                                                                                                                               
changed: [satellite.example.com] => (item={'name': 'Weekly Red Hat repository sync', 'interval': 'weekly', 'sync_date': '2022-01-01 02:02:00 UTC', 'enabled': True, 'products': ['Red Hat Satellite Capsule', 'Red Hat Enterprise Linux for x86_64']}) => 
    ansible_loop_var: item
    changed: true
    entity:
        sync_plans:
        -   created_at: 2024-11-27 16:40:59 UTC
            cron_expression: null
            description: null
            enabled: true
            foreman_tasks_recurring_logic_id: 10
            id: 1
            interval: weekly
            name: Weekly Red Hat repository sync
            next_sync: 2024-11-30 02:02:00 UTC
            organization_id: 1
            permissions:
                destroy_sync_plans: true
                edit_sync_plans: true
                view_sync_plans: true
            products:
            -   cp_id: '479'
                description: null
                id: 195
                label: Red_Hat_Enterprise_Linux_for_x86_64
                last_sync: null
                last_sync_words: null
                name: Red Hat Enterprise Linux for x86_64
                repository_count: 5
                sync_state: null
            -   cp_id: '269'
                description: null
                id: 274
                label: Red_Hat_Satellite_Capsule
                last_sync: null
                last_sync_words: null
                name: Red Hat Satellite Capsule
                repository_count: 1
                sync_state: null
            sync_date: 2022-01-01 02:02:00 +0000
            updated_at: 2024-11-27 16:40:59 UTC
        sync_plans/products:
        -   id: 1
            product_ids:
            - 274
            - 195
    item:
        enabled: true
        interval: weekly
        name: Weekly Red Hat repository sync
        products:
        - Red Hat Satellite Capsule
        - Red Hat Enterprise Linux for x86_64
        sync_date: 2022-01-01 02:02:00 UTC
evgeni commented 4 days ago

Can you try using 2022-01-01 02:02:00 +0000 in your playbook?

myllynen commented 4 days ago

Yes, that works, thanks!

evgeni commented 4 days ago

Should this become "compare dates as dates, not strings"? But at the same time: I don't think we'd get to it anytime soon