Operating System Ubuntu

Deploy Multiple WordPress Sites with Virtualmin and Ansible on Ubuntu 26.04

Use Ansible to install Virtualmin GPL on Ubuntu 26.04 and create several independent WordPress sites, each with its own user, database and domain.

This guide uses Ansible to turn a fresh Ubuntu 26.04 LTS server into a Virtualmin host, and then to create several independent WordPress sites on it, each with its own domain, system user and database. Virtualmin GPL is the free edition of the Virtualmin hosting control panel, built on Webmin. Once the playbooks exist, building a second server or adding another site is a matter of editing a variable and running one command.

Older tutorials on this topic targeted Ubuntu 16.04, which is end-of-life and no longer supported by Virtualmin. Virtualmin's current fully supported (Grade A) systems include Ubuntu 26.04 LTS and 24.04 LTS, Debian 12 and 13, and AlmaLinux and Rocky Linux 8, 9 and 10. The playbooks below are written for Ubuntu 26.04 and are the same for 24.04; Ubuntu 22.04 is not on the Grade A list.

Requirements

  • A freshly installed Ubuntu 26.04 LTS (or 24.04 LTS) server with nothing else on it. Virtualmin's installer expects a clean system.
  • At least 1 GiB of RAM for the minimal install used here. Virtualmin's documentation asks for 4 GiB or more for the full install with mail, spam and virus filtering.
  • SSH key access to the server as a user with sudo rights. The examples use deploy at 203.0.113.10.
  • A fully qualified hostname for the server itself, such as host.example.com, with a DNS record pointing to the server. Do not use a name you plan to host as a website.
  • DNS records for each WordPress domain pointing to the server.
  • A local machine (Linux, macOS or Windows with WSL) to run Ansible from.

Step 1: Install Ansible on your local machine

Ansible runs on your own computer and connects to the server over SSH. Only Python is needed on the server, and Ubuntu Server includes it. The Ansible documentation recommends installing with pipx:

pipx install --include-deps ansible

If you do not have pipx, install it first with your package manager, for example sudo apt install pipx on Debian or Ubuntu. Check the result:

ansible --version

Step 2: Create the project and inventory

Create a directory for the project:

mkdir virtualmin-ansible
cd virtualmin-ansible

Create a file named hosts.ini that tells Ansible where the server is and how to log in:

[virtualmin]
203.0.113.10 ansible_user=deploy

Test the connection. The first time, SSH asks you to confirm the server's host key:

ansible -i hosts.ini virtualmin -m ansible.builtin.ping

A reply containing "ping": "pong" means Ansible can log in and run Python on the server.

Step 3: Define your variables

Create vars.yml with the server hostname and the list of sites. Each site needs a domain, a password for its Virtualmin account and a database name. The password is also used for the WordPress administrator of that site, so make it strong and avoid quotes and backslashes:

server_fqdn: host.example.com
virtualmin_bundle: LAMP
virtualmin_type: mini

wordpress_sites:
  - domain: example.com
    password: "change-this-password-1"
    db: wp_example_com
  - domain: example.org
    password: "change-this-password-2"
    db: wp_example_org

LAMP installs Apache; set virtualmin_bundle to LEMP for Nginx. Choose carefully, because Virtualmin's documentation warns that switching later takes significant manual work. mini skips local mail, spam and virus filtering, local DNS, FTP and Jailkit, which keeps memory use low; use full if the server should also handle mail.

The file contains passwords, so encrypt it. Ansible asks you to choose a vault password:

ansible-vault encrypt vars.yml

Use ansible-vault edit vars.yml to change it later. Do not commit an unencrypted copy to version control.

Step 4: Write the playbook that installs Virtualmin

Create virtualmin.yml. It updates the system, downloads Virtualmin's official install script and runs it unattended:

- name: Install Virtualmin GPL
  hosts: virtualmin
  become: true
  vars_files:
    - vars.yml

  tasks:
    - name: Update all packages
      ansible.builtin.apt:
        update_cache: true
        upgrade: dist

    - name: Download the Virtualmin install script
      ansible.builtin.get_url:
        url: https://download.virtualmin.com/virtualmin-install.sh
        dest: /root/virtualmin-install.sh
        mode: "0700"

    - name: Run the installer (takes several minutes)
      ansible.builtin.command:
        cmd: >-
          sh /root/virtualmin-install.sh
          --bundle {{ virtualmin_bundle }}
          --type {{ virtualmin_type }}
          --hostname {{ server_fqdn }}
          --yes
        creates: /usr/sbin/virtualmin

The creates line makes the task safe to repeat: if the virtualmin command already exists, Ansible skips the installer. The options used here are documented on Virtualmin's automated installation page, which also lists others, such as --swap to have the installer create swap space on a small server.

Run the playbook:

ansible-playbook -i hosts.ini virtualmin.yml --ask-vault-pass --ask-become-pass

Leave out --ask-become-pass if deploy can use sudo without a password.

Step 5: Finish the setup in the browser

Virtualmin listens on port 10000 over HTTPS. Open:

https://host.example.com:10000

If the browser warns about the certificate, the installer could not obtain one for the hostname; you can continue and fix the certificate later. Log in with your sudo-capable user, or as root if you have set a root password. Virtualmin then walks you through a short post-installation wizard. When the wizard is done, click Check Configuration at the top of the List Virtual Servers page and resolve anything it reports.

If the page does not load, check that port 10000 is allowed in your provider's firewall. On Ubuntu the Virtualmin installer removes the ufw package, so rules you added with UFW beforehand no longer apply.

Step 6: Write the playbook that creates the WordPress sites

Virtualmin has a command-line API, virtualmin, that does everything the web interface does. Create sites.yml, which uses it to create one virtual server per domain and install WordPress into each:

- name: Create WordPress sites in Virtualmin
  hosts: virtualmin
  become: true
  vars_files:
    - vars.yml

  tasks:
    - name: List existing virtual servers
      ansible.builtin.command: virtualmin list-domains --name-only
      register: existing_domains
      changed_when: false

    - name: Create a virtual server for each site
      ansible.builtin.command:
        argv:
          - virtualmin
          - create-domain
          - --domain
          - "{{ item.domain }}"
          - --pass
          - "{{ item.password }}"
          - --desc
          - "WordPress site {{ item.domain }}"
          - --default-features
      loop: "{{ wordpress_sites }}"
      when: item.domain not in existing_domains.stdout_lines
      no_log: true

    - name: List installed web apps
      ansible.builtin.command: virtualmin list-scripts --domain {{ item.domain }} --name-only
      loop: "{{ wordpress_sites }}"
      register: installed_scripts
      changed_when: false
      no_log: true

    - name: Install WordPress into each site
      ansible.builtin.command:
        argv:
          - virtualmin
          - install-script
          - --domain
          - "{{ item.item.domain }}"
          - --type
          - wordpress
          - --version
          - latest
          - --path
          - /
          - --db
          - mysql
          - "{{ item.item.db }}"
          - --newdb
      loop: "{{ installed_scripts.results }}"
      when: "'wordpress' not in item.stdout_lines"
      no_log: true

--default-features enables the features that are switched on by default in your Virtualmin configuration (home directory, website, database and so on). list-scripts --name-only prints the short names of the web apps already installed in a virtual server, which is how the playbook knows where WordPress is still missing.

The install-script options are the ones Virtualmin's own program defines: --type wordpress is the installer's short name, --version latest picks the newest version the installer knows, --path / installs into the top of the site's public_html directory rather than a subdirectory, and --db mysql followed by a name selects the database. --newdb makes install-script create that database; without it the database must already exist, and with it the command stops if a database of that name is already there. Virtualmin's installer downloads WordPress with WP-CLI and completes the WordPress setup itself, creating the WordPress administrator with the virtual server's user name and password. no_log keeps the passwords out of Ansible's output.

Run it:

ansible-playbook -i hosts.ini sites.yml --ask-vault-pass --ask-become-pass

Step 7: Add certificates and verify

Once a domain's DNS points to the server, request a Let's Encrypt certificate for it. On the server:

sudo virtualmin generate-letsencrypt-cert --domain example.com

Check what exists:

sudo virtualmin list-domains
sudo virtualmin list-scripts --domain example.com

Then open each domain in a browser. WordPress is already set up: the front page loads, and you log in at /wp-admin/ with the virtual server's user name (the Username column of virtualmin list-domains) and the password you set for that site in vars.yml. The site title is taken from the virtual server's description; change it under Settings in the WordPress dashboard.

Adding sites and rebuilding

To add a site, run ansible-vault edit vars.yml, append an entry to wordpress_sites and run sites.yml again. Existing sites are skipped. To build another server, add its address to hosts.ini and run both playbooks.

Virtualmin and Webmin are installed from Virtualmin's own package repository, so they are updated with the rest of the system by sudo apt update && sudo apt upgrade. WordPress updates itself from its dashboard, and Virtualmin can also upgrade installed apps from each virtual server's web apps page.

Troubleshooting

  • The installer refuses to run. It requires a Grade A operating system by default and a fully qualified hostname for full installs. Read the message in the task output, or run the playbook with -v to see everything the installer printed.
  • install-script reports an unknown type. List the web apps your edition offers with sudo virtualmin list-available-scripts --name-only and use the short name shown there. WordPress is included in Virtualmin GPL.
  • You need the exact options of a command. Run virtualmin help create-domain (or any other command name) on the server.

Frequently asked questions

Why use Virtualmin instead of installing WordPress directly?

Virtualmin gives every site its own system user, home directory, database and web server configuration. A compromised plugin on one site then cannot read another site's files, and you can hand a customer a login that only sees their own site.

Can I run the playbooks more than once?

Yes. The installer task is skipped when Virtualmin is already present, and the site tasks check for existing virtual servers and existing WordPress installs before creating anything. Re-running is how you add sites.

Should I choose LAMP or LEMP?

Both run WordPress well. Apache (LAMP) is Virtualmin's default and supports the .htaccess files that many WordPress plugins write. Nginx (LEMP) uses less memory under load but needs rewrite rules in its own configuration. If you have no strong reason, keep the default.

Is the root password still needed for the web interface?

Not necessarily. Virtualmin's documentation says a sudo-capable user can normally log in instead of root, which suits servers that only allow SSH key logins and have no root password set.

Share story:

Continue reading other guides on How VPS.