ansibleyum

How to use the `yum` module to clean and make cache the yum repo in Ansible?


Ansible has the yum module,

We can use it to install a package:

​ansible all -m yum -a 'name=vim state=latest'  

but how to use it to execute the clean and make cache commands? I only know the script way:

ansible all -m shell -a 'yum clean all'
ansible all -m shell -a 'yum makecache'

So, how to use the yum module to clean and make cache the yum repo?


Solution

  • You're doing it the correct way.

    - shell: yum clean all
    

    The way you want it, is not implemented in Ansible.

    From the Docs:

    "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', issue"