Uninstalling PE from agent nodes

Uninstalling PE from agent nodes

At work we switched from using Puppet Enterprise to Ansible for a variety of reasons. After the switch I disabled the Puppet agents, but never got around to uninstalling all of them.

Recently, I ran into an issue where one server suddenly turned the Puppet agent back on and reverted changes that were made. I decided it was time to clean up the mess, but Puppet requires files from the server in order to uninstall the agent and my server was long gone.

This document covers the agent uninstall process: https://docs.puppet.com/pe/latest/install_uninstalling.html#uninstalling-pe-from-agent-nodes

I uploaded the necessary files here, in order to prevent myself or other people from installing Puppet Enterprise again to retrieve them: pe-uninstall.zip

ansibleThe next step was to create an Ansible job to copy these to the server and run the uninstall script. Easy.

https://bitbucket.org/blissjoe/ansible-remove-peagent/overview


---
- hosts: puppet
  become: true
  tasks:
  
  - name: check for pe-agent
    command: rpm -q pe-agent
    register: rpm_check
    ignore_errors: true
    
  - block:  
    - name: copy uninstall script
      copy: src=files/puppet/puppet-enterprise-uninstaller dest=/tmp/puppet-enterprise-uninstaller mode="u+rwx"
    
    - name: copy utils and answers
      copy: src=files/puppet/{{ item }} dest=/tmp/{{ item }}
      with_items:
      - utilities
      - answers.remove
    
    - name: run uninstall script
      command: "/tmp/puppet-enterprise-uninstaller -a /tmp/answers.remove"

    - name: cleanup
      file: path=/tmp/{{ item }} state=absent
      with_items:
      - utilities
      - answers.remove  
      - puppet-enterprise-uninstaller 
      
    when: rpm_check.rc == 0

Leave a Reply

Your email address will not be published. Required fields are marked *