Automated WordPress stack provisioning with Ansible — Nginx, PHP-FPM, MySQL, SFTP isolation per site.
Before running the playbook, the server must meet these requirements:
- Ubuntu 22.04 / 24.04 LTS
- SSH key added to server for your sudo user (e.g.
alex3) - SSH key must NOT be password-protected (or added to
ssh-agentbefore running) sudoconfigured without password for your user:
printf 'USERNAME ALL=(ALL) NOPASSWD: ALL\n' | sudo tee /etc/sudoers.d/USERNAME
sudo chmod 440 /etc/sudoers.d/USERNAMEpython3(for Ansible modules)python3-pymysql(for MySQL Ansible module) — installed automatically by playbook
- Ansible
>= 2.15 - Python package
passlib - Ansible collection
community.mysql
Install with:
pip install ansible passlib
ansible-galaxy collection install community.mysql- Copy example inventory:
cp inventory/hosts-example.yml inventory/hosts.yml- Fill in
inventory/hosts.ymlwith your server details:
ansible_host: YOUR_SERVER_IP
ansible_user: YOUR_SSH_USER
ansible_port: YOUR_SSH_PORT
ansible_ssh_private_key_file: ~/.ssh/YOUR_KEY- Make sure
inventory/hosts.ymlis not committed — it's in.gitignore
ansible-playbook -i inventory/hosts.yml playbooks/new_site.yml -e "domain=mysite.com"ansible-playbook -i inventory/hosts.yml playbooks/remove_site.yml -e "domain=mysite.com"From domain mysite.com |
Result |
|---|---|
| Linux user | mysite---admin |
| SFTP chroot | /var/www/mysite---admin |
| Webroot | /var/www/mysite---admin/mysite.com/public |
| PHP-FPM pool | /etc/php/8.5/fpm/pool.d/mysite---admin.conf |
| PHP socket | /run/php/php8.5-fpm-mysite.sock |
| Nginx vhost | /etc/nginx/sites-available/mysite.com |
| MySQL DB | mysite_com |
| MySQL user | mysite_com |
| SFTP password | auto-generated, stable |
| DB password | auto-generated, stable |
After deployment, credentials are saved to credentials/<domain>/credentials.txt
- Host: YOUR_SERVER_IP
- Port: 2044
- User: mysite---admin
- Password: ...
- DB: mysite_com
- User: mysite_com
- Password: ...
credentials/ is in .gitignore — never commit it!
- Nginx + FastCGI cache
- PHP 8.5 (Ondřej Surý PPA) + OPcache
- MySQL — isolated DB per site
- SFTP — chroot per site, password auth for
*---adminusers only - WordPress — latest, auto-configured