ansibledropbear

ansible apt absent not working for dropbear


I tried a simple install/uninstall ansible playbook with dropbear but not able to remove the module by setting apt state to absent.

---
# filename: install.yaml
- hosts: all
  become: yes

  tasks:
  - name: install dropbear
    tags: dropbear
    apt:
      name: dropbear
---
# filename: uninstall.yaml
- hosts: all
  become: yes

  tasks:
  - name: uninstall dropbear
    tags: dropbear
    apt:
      name: dropbear
      state: absent

When running the uninstall.yaml ansible playbook, it prints out that the task is OK and state has been changed. I ssh into the target server but the dropbear command still exist.


Solution

  • Finally get it work! Thanks to @zeitounator's hint.

    Adding autoremove: yes still not work, but after manually uninstall dropbear with apt-get remove dropbear. I found there are dependencies. I tried using a wildcard with name: dropbear*, then the dropbear is removed.

    ---
    # uninstall.yaml
    - hosts: all
      become: yes
    
      tasks:
      - name: uninstall dropbear 
        tags: dropbear
        apt:
          name: dropbear*
          state: absent
          autoremove: yes
          purge: yes
    

    I think this method might work for other packages with dependencies not able to be removed by ansible apt module using autoremove, too.

    Still don't know why the autoremove not work. It should be used for the case to remove denepencies(weired).