This playbook will install symfony demo on an ubuntu 20.04 machine. It has been tested with docker container.
Make sure you have installed all of the following prerequisites on your development machine:
- Docker - Download & Install Docker.
symfony-lemp_ubuntu20.04/
├── .config/
├── playbooks/
│ ├── roles/
│ ├── library/
│ └── main.yml
│ └── count_post.yml
│ └── http_status.yml
├── vars/
│ └── default.yml
│ └── secrets.yml
├── ansible.cfg
├── build.sh
├── run.sh
├── Dockerfile
└── inventory
└── requirements.txt
http_host
: your domain namewww_path
: your web app root foldergit_url_repository
: your git url repository to clonegit_branch
: your branch namemysql_root_password
: your root passwordmysql_database_url
: your credentiels databasedb_user
: your database userdb_password
: your database passworddb_host
: your database hostdb_port
: your database portdb_name
: your database nameapp_secret
: your symfony secretapp_env
: define dev ou prod environmentsymfony_console_path
: your symfony console absolute path
To display the contents of an encrypted ansible-vault file without modifying it, just use the view option
$ ansible-vault view vars/secrets.yml
Vault password is secret
Quick steps after cloning the repository
127.0.0.1 node-1
127.0.0.1 node-2
$ cd ansible-playbooks/symfony-lemp_ubuntu20.04
$ vi vars/default.yml
$ pip install -r requirements.txt
$ touch /var/log/ansible.log
$ chmod 640 /var/log/ansible.log
$ chown [OWNER]:[GROUP] /var/log/ansible.log
./build.sh
./run.sh # Expose port 80 from container and map with host port 8080
Check if node target is pingable
ansible all -m ping
node-1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
node-2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
Add ask-pass option is useful the first time, cause need to copy public key to the server
ansible-playbook -v -i inventory --ask-pass --ask-vault-pass playbooks/main.yml
ansible all -m raw -a 'service php8.1-fpm restart'
node-1 | CHANGED | rc=0 >>
* Restarting PHP 8.1 FastCGI Process Manager php-fpm8.1 [ OK ]
Connection to node-1 closed.
node-2 | CHANGED | rc=0 >>
* Restarting PHP 8.1 FastCGI Process Manager php-fpm8.1 [ OK ]
Connection to node-2 closed.
ansible all -m raw -a 'service nginx restart'
node-1 | CHANGED | rc=0 >>
* Restarting nginx nginx [ OK ]
Connection to node-1 closed.
node-2 | CHANGED | rc=0 >>
* Restarting nginx nginx [ OK ]
Connection to node-2 closed.
node-1 | node-2 |
---|---|
💻 http://node-1:8080/fr | 💻 http://node-2:8081/fr |
$ cd symfony-lemp_ubuntu20.04
$ ansible-playbook --ask-vault-password playbooks/http_status.yml
PLAY [Deploy Symfony Demo Application] ************************************************************************************
TASK [check-http : check that homepage returns a status 200] **************************************************************
ok: [node-2] => (item=8080)
ok: [node-1] => (item=8080)
ok: [node-2] => (item=8081)
ok: [node-1] => (item=8081)came
PLAY RECAP ****************************************************************************************************************
node-1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node-2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$ cd symfony-lemp_ubuntu20.04
$ ansible-playbook --syntax-check -i inventory playbooks/count_post.yml --ask-vault-pass
The documentation defines what the module does, execute this command to see it
$ ansible-doc -M playbooks/library count_post