Add automatic removal of metasploit if it is no longer true.

This commit is contained in:
2026-07-26 18:35:20 -07:00
parent b4e8bf6f15
commit 5710f284ba
2 changed files with 25 additions and 6 deletions
-1
View File
@@ -109,7 +109,6 @@
when: ansible_system == "FreeBSD" when: ansible_system == "FreeBSD"
- include_tasks: tasks/general/software/metasploit.yml - include_tasks: tasks/general/software/metasploit.yml
when: pentesting == true
when: provision == true when: provision == true
+25 -5
View File
@@ -5,6 +5,7 @@
set_fact: set_fact:
metasploit_installer: msfinstall metasploit_installer: msfinstall
when: ansible_system in ("Linux", "Darwin") when: ansible_system in ("Linux", "Darwin")
and pentesting == true
- name: General | Software | Metasploit | Check Install Status - name: General | Software | Metasploit | Check Install Status
stat: stat:
@@ -18,8 +19,9 @@
- "mv -fv /usr/share/keyrings/metasploit-framework.gpg /tmp/apt/metasploit-framework.gpg.old" - "mv -fv /usr/share/keyrings/metasploit-framework.gpg /tmp/apt/metasploit-framework.gpg.old"
- "mv -fv /etc/apt/sources.list.d/metasploit-framework.list /tmp/apt/metasploit-framework.list.old" - "mv -fv /etc/apt/sources.list.d/metasploit-framework.list /tmp/apt/metasploit-framework.list.old"
- "mv -fv /etc/apt/preferences.d/pin-metasploit.pref /tmp/apt/pin-metasploit.pref.old" - "mv -fv /etc/apt/preferences.d/pin-metasploit.pref /tmp/apt/pin-metasploit.pref.old"
when: ansible_system in ("Linux") and when: ansible_system in ("Linux") and ansible_pkg_mgr == "apt"
not metasploit_status.stat.exists and not metasploit_status.stat.exists
and pentesting == true
ignore_errors: true ignore_errors: true
- name: General | Software | Metasploit | Install - name: General | Software | Metasploit | Install
@@ -28,7 +30,25 @@
- "curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > {{ metasploit_installer }}" - "curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > {{ metasploit_installer }}"
- "chmod 755 {{ metasploit_installer }}" - "chmod 755 {{ metasploit_installer }}"
- "mkdir -p {{ global_bin }}" - "mkdir -p {{ global_bin }}"
- "mv -fv ./msfinstall {{ global_bin }}/{{ metasploit_installer }}" - "mv -fv ./{{ metasploit_installer }} {{ global_bin }}/{{ metasploit_installer }}"
- yes y | "{{ global_bin }}/{{ metasploit_installer }}" - yes y | "{{ global_bin }}/{{ metasploit_installer }}"
when: ansible_system in ("Linux", "Darwin") and when: ansible_system in ("Linux", "Darwin")
not metasploit_status.stat.exists and not metasploit_status.stat.exists
and pentesting == true
- name: General | Software | Metasploit | Remove (Darwin)
shell: "{{ item }}"
loop:
- "/opt/metasploit-framework/bin/msfremove"
when: ansible_system in ("Darwin")
and not metasploit_status.stat.exists
and pentesting == false
- name: General | Software | Metasploit | Remove (APT)
shell: "{{ item }}"
loop:
- "apt purge metasploit-framework"
- "apt autoremove --purge"
when: ansible_system in ("Linux") and ansible_pkg_mgr == "apt"
and not metasploit_status.stat.exists
and pentesting == false