Could anyone please support with equivalent tasks for clean and remove ?
yum clean expire-cache
yum -y remove packageX-S
yum -y install packageX-S
I got install already...
- name: deploy
yum:
name: llc-html-clients-S
state: latest
Could anyone please support with equivalent tasks for clean and remove ?
yum clean expire-cache
yum -y remove packageX-S
yum -y install packageX-S
I got install already...
- name: deploy
yum:
name: llc-html-clients-S
state: latest
Here are your equivalent tasks:
- name: clean
command: yum clean expire-cache
- name: remove
yum:
name: pkg-to-remove
state: absent
- name: install
yum:
name: pkg-to-install
state: present
Installing and removing is done with the same module yum.
When installing would test the installed or present state, removing is about testing removed or absent state.
Install:
- name: install
yum:
name: pkg-to-install
state: present
Take care: yum install and state: latest are not the same, when the yum command will install if the package is absent and do nothing if it is present already, state: latest will do an install if the package is absent but also a yum update pkg-to-install if the package is not at its latest version.
The real equivalent is state: present.
presentandinstalledwill simply ensure that a desired package is installed.
latestwill update the specified package if it's not of the latest available version.
Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#parameter-state
Remove:
- name: remove
yum:
name: pkg-to-remove
state: absent
Then for the clean, sadly, there was a choice to not implement it, as this is not something that can be done in an idempotent way.
See this note on yum module page
- The yum module does not support clearing yum cache in an idempotent way, so it was decided not to implement it, the only method is to use command and call the yum command directly, namely “command: yum clean all”
https://github.com/ansible/ansible/pull/31450#issuecomment-352889579
Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#notes
So as pointed in the note, you could actually go by a simple command.
- name: clean
command: yum clean expire-cache
So those are equivalent:
yum clean expire-cache
yum -y remove pkg-to-remove
yum -y install pkg-to-install
- name: clean
command: yum clean expire-cache
- name: remove
yum:
name: pkg-to-remove
state: absent
- name: install
yum:
name: pkg-to-install
state: present