0

I want to remove an application on a remote node using ansible. Below is my playbook. How do i provide a range to the uninstall task to repeat till no packages are left.

---

 hosts: all



 tasks:
 - name: check-packages
  shell: rpm -qa | grep -e "^\(HPOpr\|HPE\|HPOv\|HPBsm\|MIB2Policy\|HPOMi\)"
  register: output

- name: uninstall
  shell: rpm -e   {{ output.stdout_lines.0 }}   --nodeps

I tried with range operator

   shell: rpm -e   {{ output.stdout_lines[:40] }}   --nodeps

But it was not working.

1
- name: uninstall
  package:
    name: "{{ item }}"
    state: absent
  with_list: "{{ output.stdout_lines }}"

Or if you use Ansible 2.5 or newer, replace with_list with loop.

You can also do it in one go:

- name: uninstall
  package:
    name: "{{ output.stdout_lines }}"
    state: absent
  • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) . – achak01 Sep 11 '18 at 8:45
  • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks. – mhutter Sep 11 '18 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.