Skip to content

Commit

Permalink
PMM-7 Fix removal of default vagrant user. (#3595)
Browse files Browse the repository at this point in the history
  • Loading branch information
talhabinrizwan committed Feb 9, 2025
1 parent 1dec00c commit eccbb87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ fetch-el9:
-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

# # 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
Expand Down
34 changes: 34 additions & 0 deletions build/ansible/roles/ami-ovf/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,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 eccbb87

Please sign in to comment.