Skip to content

Commit

Permalink
HD-26283 Fix removal of default vagrant user for OVA (#3596)
Browse files Browse the repository at this point in the history
* PMM-7 Fix removal of default vagrant user.

* PMM-7 Fix removal of default vagrant user.
  • Loading branch information
talhabinrizwan committed Feb 9, 2025
1 parent d989d76 commit 6aa1114
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
13 changes: 11 additions & 2 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ fetch:
-o ${PACKER_CACHE_DIR}/id_rsa_vagrant
chmod 600 ${PACKER_CACHE_DIR}/id_rsa_vagrant

# Add the box using Vagrant
test -f ${PACKER_CACHE_DIR}/box/oracle9.ova \
|| curl -fL https://pmm-build-cache.s3.us-east-2.amazonaws.com/VBOXES/oracle9-202407.23.0.box -o ${PACKER_CACHE_DIR}/box/oracle9.ova

test -f ${PACKER_CACHE_DIR}/box/box.ovf \
|| VAGRANT_HOME=${PACKER_CACHE_DIR}/box vagrant box add bento/oraclelinux-9 --box-version ${BOX_VERSION} --provider virtualbox
|| tar -C ${PACKER_CACHE_DIR}/box -xvf ${PACKER_CACHE_DIR}/box/oracle9.ova

test -f ${PACKER_CACHE_DIR}/box/box.ovf \
|| cp -rp ${PACKER_CACHE_DIR}/box/boxes/bento-VAGRANTSLASH-oraclelinux-9/${BOX_VERSION}/amd64/virtualbox/* ${PACKER_CACHE_DIR}/box

# # Add the box using Vagrant
# test -f ${PACKER_CACHE_DIR}/box/box.ovf \
# || VAGRANT_HOME=${PACKER_CACHE_DIR}/box vagrant box add bento/oraclelinux-9 --box-version ${BOX_VERSION} --provider virtualbox

# test -f ${PACKER_CACHE_DIR}/box/box.ovf \
# || cp -rp ${PACKER_CACHE_DIR}/box/boxes/bento-VAGRANTSLASH-oraclelinux-9/${BOX_VERSION}/amd64/virtualbox/* ${PACKER_CACHE_DIR}/box

deps:
mkdir -p ${PACKER_CACHE_DIR} ~/bin || :
curl -fL https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -o ${PACKER_CACHE_DIR}/packer.zip
Expand Down
34 changes: 34 additions & 0 deletions build/packer/ansible/roles/ami-ovf/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,37 @@

- name: PMM | Delete Azure user
shell: cd /tmp; nohup sh -c "trap '/usr/sbin/waagent -force -deprovision+user && sync' EXIT; sleep 600" </dev/null >/dev/null 2>&1 &

- name: Lock vagrant user
ansible.builtin.user:
name: vagrant
password_lock: true
when: ansible_virtualization_type == "virtualbox"

- name: Configure systemd service to remove vagrant user
block:
- name: Create systemd service file
copy:
dest: /etc/systemd/system/remove-vagrant.service
content: |
[Unit]
Description=Remove vagrant user on first boot
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/userdel -r vagrant
ExecStartPost=/usr/bin/touch /etc/remove-vagrant-done
[Install]
WantedBy=multi-user.target
ConditionPathExists=!/etc/remove-vagrant-done
- name: Reload systemd to recognize the new service
command: systemctl daemon-reload

- name: Enable the remove-vagrant service
systemd:
name: remove-vagrant
enabled: true
when: ansible_virtualization_type == "virtualbox"

0 comments on commit 6aa1114

Please sign in to comment.