Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
authors:
- Eric Ames (ericcames)
dependencies:
"amazon.aws": ">=7.2.0"
"servicenow.itsm": ">=2.4.0"
amazon.aws: ">=7.2.0"
servicenow.itsm: ">=2.4.0"
license_file: LICENSE
name: redhat_automated_patching
description: Use Ansible, Insights and Servicenow to demo automated patching.
Help your control owners demostrate continuous compliance to your auditors.
description: Use Ansible, Insights and Servicenow to demo automated patching. Help your control owners demostrate continuous compliance to your auditors.
namespace: ericcames
readme: README.md
repository: https://github.com/ericcames/redhat.automated.patching
Expand All @@ -24,4 +23,4 @@ tags:
- dailydemo
- sales
- insights
version: 0.0.0
version: "0.0.0"
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
requires_ansible: ">=2.12.0"
requires_ansible: ">=2.12.0"
1 change: 0 additions & 1 deletion playbooks/get_insights_inventory_id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
connection: local

tasks:

- name: Include the get_insights_inventory_id role
ansible.builtin.include_role:
name: get_insights_inventory_id
1 change: 0 additions & 1 deletion playbooks/get_my_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
connection: local

tasks:

- name: Print hostname
ansible.builtin.debug:
var: inventory_hostname
Expand Down
1 change: 0 additions & 1 deletion playbooks/process_cves.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
connection: local

tasks:

- name: Include the process_cves role
ansible.builtin.include_role:
name: process_cves
2 changes: 1 addition & 1 deletion playbooks/update_change_tkt_worknotes.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
- name: Update the change ticket
hosts: localhost
connection: local

tasks:

- name: Include the update_change_ticket_worknotes role
ansible.builtin.include_role:
name: update_change_ticket_worknotes
3 changes: 1 addition & 2 deletions roles/process_cves/meta /main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
galaxy_info:
role_name: process_cves
author: Eric Ames (ericcames)
description: For each cve with a playbook apply the fix.
For each cves with no playbook create a problem record.
description: For each cve with a playbook apply the fix. For each cves with no playbook create a problem record.
license: MIT License
min_ansible_version: "2.12"
20 changes: 10 additions & 10 deletions roles/process_cves/tasks/launch_playbooks.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
- name: Update job template
ansible.controller.job_template:
awx.awx.job_template:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
name: 'Insights CVE R1000 "The Remediator"'
name: Insights CVE R1000 "The Remediator"
job_type: run
organization: AmesCO
inventory: "AAP Managed Inventory"
inventory: AAP Managed Inventory
project: RedHatInsightsPlaybooks
playbook: "{{ item.number }}.yml"
credentials:
- AWS Machine Credential - Ames

- name: Run job template
register: job
ansible.controller.job_launch:
awx.awx.job_launch:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
job_template: 'Insights CVE R1000 "The Remediator"'
job_template: Insights CVE R1000 "The Remediator"

- name: Update the status for ticket
servicenow.itsm.change_request_task:
Expand All @@ -28,24 +28,24 @@
work_notes: "Launched AAP Job ID: {{ job.id }}"

- name: Update job template back to default playbook
ansible.controller.job_template:
awx.awx.job_template:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
name: 'Insights CVE R1000 "The Remediator"'
name: Insights CVE R1000 "The Remediator"
job_type: run
organization: AmesCO
inventory: "AAP Managed Inventory"
inventory: AAP Managed Inventory
project: RedHatInsightsPlaybooks
playbook: hello_world.yml
credentials:
- AWS Machine Credential - Ames

- name: Wait for a job max 120 seconds
register: job_status
ansible.controller.job_wait:
awx.awx.job_wait:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
job_id: '{{ job.id }}'
job_id: "{{ job.id }}"
timeout: 120

- name: Closing task
Expand Down
26 changes: 14 additions & 12 deletions roles/process_cves/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
- name: Determine that both AAP and Machine credentials are set
ansible.builtin.assert:
that:
- "lookup('ansible.builtin.env', 'CONTROLLER_USERNAME') !=''"
- "lookup('ansible.builtin.env', 'CONTROLLER_HOST') !=''"
- "lookup('ansible.builtin.env', 'CONTROLLER_PASSWORD') !=''"
- lookup('ansible.builtin.env', 'CONTROLLER_USERNAME') !=''
- lookup('ansible.builtin.env', 'CONTROLLER_HOST') !=''
- lookup('ansible.builtin.env', 'CONTROLLER_PASSWORD') !=''
fail_msg:
- "Red Hat Ansible Automation Platform credential is not set"
- "Please assign correct credentials to the Job Template"
- Red Hat Ansible Automation Platform credential is not set
- Please assign correct credentials to the Job Template

- name: Set a fact for controller_host
ansible.builtin.set_fact:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"

- name: Create a new token using username/password
ansible.controller.token:
awx.awx.token:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_username: "{{ lookup('ansible.builtin.env', 'CONTROLLER_USERNAME') }}"
controller_password: "{{ lookup('ansible.builtin.env', 'CONTROLLER_PASSWORD') }}"
Expand Down Expand Up @@ -65,7 +65,9 @@
loop: "{{ task_numbers_are_here['results'] }}"
when: item.changed == true
ansible.builtin.set_fact:
chg_tkt_list: "{{ chg_tkt_list | default([]) + [{'number': item.record.number, 'short_description': item.record.short_description, 'task_sys_id': item.record.sys_id, 'change_request_sys_id': item.record.change_request, 'cmdb_ci': item.record.cmdb_ci, 'insights_id': my_insights_inventory_id, 'cve_id': item.record.user_input}] }}"
chg_tkt_list: "{{ chg_tkt_list | default([]) + [{'number': item.record.number, 'short_description': item.record.short_description, 'task_sys_id': item.record.sys_id,
'change_request_sys_id': item.record.change_request, 'cmdb_ci': item.record.cmdb_ci, 'insights_id': my_insights_inventory_id, 'cve_id': item.record.user_input}]
}}"

- name: Print out Change Task Tickets list
ansible.builtin.debug:
Expand All @@ -88,7 +90,8 @@
loop: "{{ problem_numbers_are_here['results'] }}"
when: item.changed == true
ansible.builtin.set_fact:
pbm_tkt_list: "{{ pbm_tkt_list | default([]) + [{'number': item.record.number, 'short_description': item.record.short_description, 'sys_id': item.record.sys_id, 'cmdb_ci': item.record.user_input}] }}"
pbm_tkt_list: "{{ pbm_tkt_list | default([]) + [{'number': item.record.number, 'short_description': item.record.short_description, 'sys_id': item.record.sys_id,
'cmdb_ci': item.record.user_input}] }}"

- name: Generate playbooks to remediate vulnerabilities
register: my_playbooks
Expand Down Expand Up @@ -149,7 +152,7 @@
ansible.builtin.copy:
dest: "{{ process_cves_local_repo }}/{{ item.item.number }}.yml"
content: "{{ item.content }}"
mode: '0644'
mode: "0644"

# - name: Update playbooks to use the public facing dns name
# loop: "{{ my_playbooks['results'] }}"
Expand Down Expand Up @@ -198,12 +201,11 @@
ansible.builtin.shell: git push

- name: Kick off a project sync
ansible.controller.project_update:
awx.awx.project_update:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
project: RedHatInsightsPlaybooks


- name: Pausing for 20 seconds to allow for the project sync up to finish
ansible.builtin.pause:
seconds: 20
Expand All @@ -214,7 +216,7 @@
file: tasks/launch_playbooks.yml

- name: Remove automated patching token
ansible.controller.token:
awx.awx.token:
controller_host: "{{ lookup('ansible.builtin.env', 'CONTROLLER_HOST') }}"
controller_oauthtoken: "{{ controller_token }}"
existing_token: "{{ controller_token }}"
Expand Down