Skip to content

Commit

Permalink
chore: clean packer user
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Jun 16, 2024
1 parent 43dcb23 commit cc02588
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/scripts/azure-new-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ else
IMAGE_NAME="redhat:rhel-cvm:9_3_cvm_sev_snp:latest"
fi

IMAGE_NAME="/subscriptions/e04f52be-d51f-43fe-95f8-d63a8fc91464/resourceGroups/packer-snp/providers/Microsoft.Compute/galleries/cosmian_packer/images/base-image-${DISTRIB}-${TECHNO}/versions/0.1.5"

az vm create -g packer-snp -n "$NAME" \
--image "$IMAGE_NAME" \
--security-type ConfidentialVM \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
for i in {1..1}
do
echo "Iteration: $i"
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u $SSH_USER --private-key="$HOME/packer.pem" -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }} -e '{ "check_app_test_reboot": false, "check_cosmian_vm_test_reboot": false, "reboot_allowed": false }' --tags playbook-base-image,playbook-${{ inputs.product }},check-${{ inputs.product }}
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u $SSH_USER --private-key="$HOME/packer.pem" -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }} -e '{ "check_app_test_reboot": false, "check_cosmian_vm_test_reboot": false, "reboot_allowed": false }' --tags playbook-base-image,playbook-${{ inputs.product }},check-${{ inputs.product }} --skip-tags role-cleanup
done
- name: Stop and delete AWS instance
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/azure_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
for i in {1..1}
do
echo "Iteration: $i"
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u cosmian -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }}
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u cosmian -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }} --skip-tags role-cleanup
done
- name: Stop and delete Azure instance
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gcp_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
for i in {1..1}
do
echo "Iteration: $i"
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u cosmian -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }}
ansible-playbook ${{ inputs.product }}-playbook.yml -i ${IP_ADDR}, -u cosmian -e cosmian_vm_version=$COSMIAN_VM_VERSION -e cosmian_kms_version=${{ inputs.kms-version }} -e cosmian_ai_runner_version=${{ inputs.ai-runner-version }} --skip-tags role-cleanup
done
- name: Stop and delete GCP instance
Expand Down
2 changes: 2 additions & 0 deletions ansible/ai-runner-packer-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
become: true
roles:
- ai_runner
- role: cleanup
tags: role-cleanup
7 changes: 7 additions & 0 deletions ansible/base-image-packer-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@
- name: Display Security updates
ansible.builtin.debug:
var: dnf_security_update

- name: Clean base image
hosts: all
become: true
roles:
- role: cleanup
tags: role-cleanup
2 changes: 2 additions & 0 deletions ansible/cosmian-vm-packer-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- check_cpu
- role: cosmian_vm_agent
tags: role_cosmian_vm_agent
- role: cleanup
tags: role-cleanup
2 changes: 2 additions & 0 deletions ansible/kms-packer-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
become: true
roles:
- kms
- role: cleanup
tags: role-cleanup
40 changes: 40 additions & 0 deletions ansible/roles/cleanup/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# tasks file for ansible/roles/cleanup

- name: Find all authorized_keys files
ansible.builtin.find:
paths:
- /home
- /root
recurse: true
patterns: authorized_keys
register: authorized_keys

- name: Display authorized_keys
ansible.builtin.debug:
var: authorized_keys

- name: Remove found authorized_keys files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ authorized_keys.files }}"
when: authorized_keys.matched > 0

- name: Find all authorized_keys files
ansible.builtin.find:
paths:
- /home
- /root
recurse: true
patterns: authorized_keys
register: authorized_keys

- name: Display authorized_keys authorized_keys
ansible.builtin.debug:
var: authorized_keys

- name: Fail if authorized_keys files are found
ansible.builtin.fail:
msg: "authorized_keys files found in the system!"
when: authorized_keys.matched > 0

0 comments on commit cc02588

Please sign in to comment.