In the previous article we showed you how we created our infrastructure as code. This article describes how to configure services within our EC2 instances.
Provision Backend
Let’s start with a bash script to run the playbooks:
1 2 3 4 5 6 7 8 |
./provision_nuvola_backend.sh --limit "tag_nuvola_type_${ENV}_backend" ./provision_nuvola_dbserver.sh --limit "tag_nuvola_type_${ENV}_database" ./provision_nuvola_routine.sh --limit "tag_nuvola_type_${ENV}_routine" if [ "$ENV" != "prod" ]; then ./nuvola-init-not-prod-env.sh --env ${ENV} ./deploy_nuvola.sh --limit "tag_nuvola_type_${ENV}_backend" --env ${ENV} fi |
Here is the playbook used to configure backend services:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
- hosts: all vars_files: - vars/system.yml - vars/packages.yml - vars/php_prod.yml - vars/vars_newrelic.yml - vars/vars_backend.yml - vars/vars_backend_secure.yml - "inventories/group_vars/regions.yml" handlers: - include: roles/newrelic/handlers/main.yml tasks: - include: roles/init/tasks/init_upgrade_generic.yml tags: init - include: roles/init/tasks/init_nuvola_dns_updater.yml tags: dns - include: roles/init/tasks/init_nuvola_backend.yml tags: init - include: roles/php7/tasks/php7_prod.yml tags: php - include: roles/nginx/tasks/nginx_prod.yml tags: nginx - include: roles/newrelic/tasks/newrelic_php7.yml tags: newrelic - include: roles/rabbitmq/tasks/rabbitmq_php.yml tags: rabbitmq_php - include: roles/logstash/tasks/logstash_forwarder_all.yml tags: logstash - include: roles/cloudwatch-logs-agent/tasks/cloudwatch-logs-agent.yml tags: cloudwatch - include: roles/webserver/tasks/finalize.yml tags: webserver - include: roles/deploy-nuvola/tasks/auto-deploy.yml tags: auto-deploy |
Let’s focus on php configuration tasks.
The following file:
1 2 |
- include: roles/php7/tasks/php7_prod.yml tags: php |
contains:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
- include: php7_all.yml - name: PHP7 ALL | Set php.ini CLI template: src=roles/php7/templates/nuvola/php.ini.cli.j2 dest=/etc/php/{{ php_version }}/cli/php.ini become: true become_user: root - name: PHP7 ALL | Set php.ini web for php-fpm template: src=roles/php7/templates/nuvola/php.ini.web.j2 dest=/etc/php/{{ php_version }}/fpm/php.ini become: true become_user: root - name: PHP7 ALL | Set apcu.ini template: src=roles/php7/templates/nuvola/apcu.ini.j2 dest=/etc/php/{{ php_version }}/mods-available/apcu.ini become: true become_user: root - name: PHP7 ALL | Set opcache.ini template: src=roles/php7/templates/nuvola/opcache.ini.j2 dest=/etc/php/{{ php_version }}/mods-available/opcache.ini become: true become_user: root |
and the following include:
1 |
- include: php7_all.yml |
contains:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
- name: PHP7 ALL | add APT PHP7 ppa apt_repository: repo='ppa:ondrej/php' state=present become: true become_user: root - name: PHP7 ALL | install php packages apt: pkg={{ item }} state=latest update_cache=yes become: true become_user: root with_items: '{{ php7_packages }}' - name: PHP7 ALL | Enable php modules command: phpenmod {{ item }} become: true become_user: root with_items: - mcrypt - imap - curl |
So we’ve just seen how to create the infrastructure, instances and configuration of our application on AWS.
We’ve written everything as code, so we can destroy and recreate our infrastructure very quickly and with different environments.
In the next article we will show you how we automated the management of the names of our services with Route53!