Using RPM module in Ansible to remove a package

10,997

That is because your command is not idempotent. I.e., once those packages are removed then your command result in rpm -e --nodeps without any other arguments. Which results in the error message you mentioned.

There is ansible module yum https://docs.ansible.com/ansible/latest/modules/yum_module.html which do a better job rather than calling rpm from a shell.

- name: remove xorg packages
  yum:
    name: xorg-X11*
    state: absent
Share:
10,997

Related videos on Youtube

dude0786
Author by

dude0786

Updated on June 04, 2022

Comments

  • dude0786
    dude0786 almost 2 years

    I am trying to delete a package in the Ansible playbook, but it fails. Error is rpm: no packages given for erase. Below is the task i am trying to run.

    - name: remove the X Windows System packages
      shell: rpm -e --nodeps `yum list installed |grep xorg-X11* |cut -d  ' ' -f1`
    

    I tried this manually and it works, Is there any separate module like rpm mpdule to execute this task in the ansible playbook.

    Thank you..

  • dude0786
    dude0786 almost 6 years
    Hi, Thanks for the reply Here, in this command it will delete all the files. I want some dependencies not to be deleted. Is there any way we can exclude the dependencies.. ?
  • robsiemb
    robsiemb over 4 years
    Hey @user12217164, welcome to StackOverflow and thanks for answering this question! It frequently can make an even better answer to include an explanation of code you provide, as opposed to just providing the code itself, so that current and future readers can understand why this is a correct solution. See more at how to answer. Thanks!
  • udondan
    udondan about 4 years
    This is running yum list against the control host, while the shell is executed on the target hosts. Therefore this only works when control-host == target-host