This excercise will show you how to use Ansible to install fully functional Wordpress.
In order to successfully run the Ansible excercise, you have to install:
After installation, you need to create two Vagrant machines, using this Vagrantfile
To provision the machines, execute vagrant up
in the directory where Vagrant file is. To check the status, use vagrant status
. To connect to one of the machines, use vagrant ssh <machine_name>
. And finally, to destroy both boxes, run vagrant destroy -f
.
Execute this sequence on ansiblehost
ssh-keygen -t ed25519
cat .ssh/id_ed25519.pub
(or the name generated)
Copy the key.
From the host machine login to ansiblenode vagrant ssh ansiblenode
, and execute
echo "<insert your public key here" >> .ssh/authorized_keys
Come back to ansiblehost. Add ssh key to ssh-agent.
eval $(ssh-agent)
ssh-add .ssh/<keyname>
Now you should be able to login to ansiblenode
. IP of the box is in the Vagrantfile.
ssh vagrant@10.100.198.189
You successfuly established connection from host to node.
Install required packages by executing sudo apt update && sudo apt install -y python3.8 python3-pip virtualenv
Update version of Python in the system sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
In /datanode
directory you have two files. Copy both of them to you home directory.
Execute
chmod 755 envprep.sh
./envprep.sh
run . ansible/bin/activate
. Prompt should indicate that you have active virtualenv (for example (ansible) vagrant@ansiblehost:
)
Navigate to /datanode/ansible
directory. Prepare vault file, even if will not be used now.
echo testpassword > vault_file
Execute ansible --version
to confirm installation.
Now it is time to test if ansible is able to connect to ansiblenode
. Simply execute this ad-hoc command:
ansible vagrant_boxes -i inventory -a "hostname"
You should receive:
10.100.198.189 | CHANGED | rc=0 >>
ansiblenode
If this is correct, you are ready to run playbooks.
If you wish to not run virtualenv and ansible configurations, you can put it into provisioning scripts.
Execute the playbook against inventory
file. To what hosts - it is defined in first lines of provision.yml
.
ansible-playbook -i inventory provision.yml
Ansible playbook is copied from here. If time allows, I'll update it to newest version. Someday ;)