diff --git a/defaults/main.yml b/defaults/main.yml index c8db0e7..af872b6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -11,3 +11,6 @@ nessus_agent_package: 'NessusAgent' nessus_agent_host: cloud.tenable.com nessus_agent_port: 443 + +nessus_manage: True +nessus_install: True diff --git a/handlers/main.yml b/handlers/main.yml index c91da15..5bee234 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,3 +2,4 @@ - name: restart nessusagent service: name=nessusagent state=restarted + when: nessus_manage diff --git a/tasks/main.yml b/tasks/main.yml index 96a8967..80e90e8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,35 +1,38 @@ --- +- block: + - name: Install Nessus Agent from repo + package: + name: "{{nessus_agent_package}}" + update_cache: yes + cache_valid_time: "{{apt_cache_valid_time | default (3600)}}" + when: "'.deb' not in nessus_agent_package" -- name: Install Nessus Agent from repo - package: - name: "{{nessus_agent_package}}" - update_cache: yes - cache_valid_time: "{{apt_cache_valid_time | default (3600)}}" - when: "'.deb' not in nessus_agent_package" + - name: Install Nessus Agent from .deb package + apt: deb={{nessus_agent_package}} + when: "'.deb' in nessus_agent_package" + when: nessus_install -- name: Install Nessus Agent from .deb package - apt: deb={{nessus_agent_package}} - when: "'.deb' in nessus_agent_package" +- block: + - name: Check agent link status + command: /opt/nessus_agent/sbin/nessuscli agent status + become: yes + ignore_errors: yes + register: nessus_link -- name: Check agent link status - command: /opt/nessus_agent/sbin/nessuscli agent status - become: yes - ignore_errors: yes - register: nessus_link + - name: Configure Nessus Agent + command: > + /opt/nessus_agent/sbin/nessuscli agent link + --key={{nessus_agent_key}} + --host={{nessus_agent_host}} + --port={{nessus_agent_port}} + --groups="{{nessus_agent_group}}" + become: yes + when: nessus_link|failed + notify: restart nessusagent -- name: Configure Nessus Agent - command: > - /opt/nessus_agent/sbin/nessuscli agent link - --key={{nessus_agent_key}} - --host={{nessus_agent_host}} - --port={{nessus_agent_port}} - --groups="{{nessus_agent_group}}" - become: yes - when: nessus_link|failed - notify: restart nessusagent - -- name: Ensure nessusagent is started - service: - name: nessusagent - state: started - enabled: yes + - name: Ensure nessusagent is started + service: + name: nessusagent + state: started + enabled: yes + when: nessus_manage