简体   繁体   English

在Ansible中使用RPM模块删除软件包

[英]Using RPM module in Ansible to remove a package

I am trying to delete a package in the Ansible playbook, but it fails. 我正在尝试删除Ansible剧本中的程序包,但失败。 Error is rpm: no packages given for erase . 错误是rpm:没有提供要擦除的软件包 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. 我手动尝试过,它可以正常工作,是否有任何单独的模块(例如rpm mpdule)在ansible剧本中执行此任务。

Thank you.. 谢谢..

That is because your command is not idempotent. 那是因为您的命令不是幂等的。 Ie, once those packages are removed then your command result in rpm -e --nodeps without any other arguments. 即,一旦删除了这些软件包,则您的命令将导致rpm -e --nodeps而不包含任何其他参数。 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. 有一个ansible模块yum https://docs.ansible.com/ansible/latest/modules/yum_module.html ,它比从shell调用rpm做得更好。

- name: remove xorg packages
  yum:
    name: xorg-X11*
    state: absent
- name: remove xorg packages
  shell: rpm -e --nodeps {{ item }}
  with_lines:
    - "yum list installed |grep xorg-X11* |cut -d  ' ' -f1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM