Difficulty: Advanced
Estimated Time: 30-45 minutes

Now, you'll combine a little bit of everything you've learned and launch a fully functional WordPress blog.

You’ll install all of the required dependencies, fetch the WordPress source files from their release page, and automatically install it.


At this point, you could destroy your environment and spin it up and everything would be the same. Pending a successful install, just like you saw in Ansible Inventory, Ansible's objective is to establish desired stated and keep it that way.

If you'd like you can test this yourself, if there's time. Ansible will run and automatically provision your WordPress install for you. It may take a few minutes, as it’s installing all of your dependencies as well as configuring WordPress, but it will work. The great thing is, of course, all your information will still be available.

Next: Congratulations! You have completed the Ansible section. See your instructor for instruction. Also, feel free to go back and re-do any of the scenarios you've previously completely.

Ansible-Installing Wordpress

Step 1 of 11

Environment Configuration

Like we've already seen, you start by creating a simple playbook that shows that Ansible can run against your host machine.

We've already created a playbook.yml file, but it won't show up until you add code to it.

1. Go ahead and list the contents of your working directory to confirm:


2. Now, you'll specify which hosts the playbook should run on, as well as a set of tasks to run. For now, you'll just implement the ping module for now, like before:

--- - hosts: all become: true tasks: - name: Make sure we can connect ping:

3. So, now that you've added some code to the file, confirm it's present in your working directory:


4. At this point, you should run ansible-playbook to prove that you can connect to the host. We do that by running our playbook against our localhost, like before:

ansible-playbook -i 'localhost,' -c local playbook.yml

Installing PHP

1. Now that you know Ansible will run, let’s install PHP. Add the following to your playbook in the tasks section:

# PHP - name: Add the ondrej PHP PPA apt_repository: repo='ppa:ondrej/php'

Note: Remember, PPA stands for Personal Package Archive and it's what's used to assist the installation process.

2. Once that’s installed, the next step is to install PHP. As you’ve added a PPA, you’ll want to update the apt package cache:

- name: Update the apt cache apt: update_cache=yes cache_valid_time=3600 - name: Install PHP apt: name=php state=present

3. Run Ansible again after adding these tasks, to make sure it is completed successfully.

ansible-playbook -i 'localhost,' -c local playbook.yml

Note: If your playbook doesn't run successfully, the changes are it's just a syntax error. Check your code, make any needed changes, and then run Ansible again.

4. Once you’ve successfully run your playbook, run which php to make sure that it yields something similar to the following:

which php



5. If that looks good, continue by installing all of the other PHP packages that you’ll need. Let’s use with_items to make the playbook easier to read though. So, delete the previous task "Install PHP", then copy and paste the following into its place in the playbook:

    - name: Install PHP
      apt: name={{item}} state=present
        - php
        - php-fpm
        - php-mysql
        - php-xml

Note: You're only to change the "Install PHP" section! You're using the with_items to wrap your request and include additional PHP packages.

6. Unfortunately, installing PHP also installs Apache2. You don’t want to use that in this exercise. There’s no way around this, but you can remove it as soon as it’s installed by adding the following task to your playbook:

- name: Remove apache2 apt: name=apache2 state=absent

7. Also, because Apache automatically creates its own index.html file, you'll need to add the following to your playbook in oder to remove it.

- name: Remove apache2 index.html file: state: absent path: /var/www/html/index.html

8. Run Ansible once again to check functionality, before moving on:

ansible-playbook -i 'localhost,' -c local playbook.yml

Great job!