Need Help for Install/Upgrade/Downgrade

I want to use simple single task for install/upgrade/downgrade . All 3 cases , I want to handle in one task:
Currently I use 2 tasks:
For Install:

  • name: Install RPMs
    yum:
    name: ‘{{ rpm_list }}’
    state: ‘latest’
    enablerepo: ‘{{ my_repos_names }}’
    disable_gpg_check: ‘{{ my_allow_unsigned_rpms }}’
    update_cache: ‘{{ my_update_cache }}’
    environment: “{{ proxy_env }}”

For upgrade/downgrade I rely on calling below from shell module:

  • name: “Performing Distribution Synchronization”
    shell: yum distro-sync -y --disablerepo=“{{repo_to_disable|default(‘*’)}}” --enablerepo=“{{ Repo_to_enable}}”
    Since distro-sync option of yum works on already installed rpms.( Yum does not have anything for downgrading cases , already some issues on this on github)

How i can achieve all 3 operations from single task, any idea ?

I want to use simple single task for install/upgrade/downgrade . All 3 cases , I want to handle in one task:
Currently I use 2 tasks:
For Install:
- name: Install RPMs
yum:
name: '{{ rpm_list }}'
state: 'latest'
enablerepo: '{{ my_repos_names }}'
disable_gpg_check: '{{ my_allow_unsigned_rpms }}'
update_cache: '{{ my_update_cache }}'
environment: "{{ proxy_env }}"

For upgrade/downgrade I rely on calling below from shell module:

- name: "Performing Distribution Synchronization"
shell: yum distro-sync -y --disablerepo="{{repo_to_disable|default('*')}}" --enablerepo="{{ Repo_to_enable}}"
Since distro-sync option of yum works on already installed rpms.( Yum does not have anything for downgrading cases ,
already some issues on this on github)

How i can achieve all 3 operations from single task, any idea ?

What are your objectives to do it in one task?

Regards
        Racke

I am trying to see if this 2 tasks can be optimized or written in single task . Nothing special , just for redundant purpose.

I am trying to see if this 2 tasks can be optimized or written in single task . Nothing special , just for redundant
purpose.

Unless you are going to write your own Ansible module, this doesn't make sense to me.

Regards
        Racke

Assume if this can be brought into. Ansible module . Then any way. If u know