Ansible/Yeti: Difference between revisions
From charlesreid1
| Line 47: | Line 47: | ||
Also see [[Ansible/Vagrant]]. | Also see [[Ansible/Vagrant]]. | ||
==Inventory file== | ==Inventory file: hosts== | ||
Info for the inventory file (port numbers) can be obtained with: | Info for the inventory file (port numbers) can be obtained with: | ||
| Line 56: | Line 56: | ||
The corresponding inventory file looks like this: | The corresponding inventory file looks like this: | ||
'''<code>hosts</code>:''' | |||
<pre> | <pre> | ||
Revision as of 05:56, 10 December 2018
Walkthrough of creating an Ansible playbook for yeti.
a) found pyenv playbook online. use this.
b) flailing with vagrant.
Setup
Before we start, we want to have the following:
- repository where our playbook will go (https://github.com/charlesreid1/dahak-yeti)
- Vagrantfile for running vagrant machines for testing our playbook
Vagrantfile
Here we give a Vagrantfile that will start three separate nodes. This is important to test yeti's ability to handle multiple machines.
Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Use the same key for each machine
config.ssh.insert_key = false
config.vm.define "vagrant1" do |vagrant1|
vagrant1.vm.box = "ubuntu/xenial64"
vagrant1.vm.network "forwarded_port", guest: 80, host: 8877
vagrant1.vm.network "forwarded_port", guest: 443, host: 7443
end
config.vm.define "vagrant2" do |vagrant2|
vagrant2.vm.box = "ubuntu/xenial64"
vagrant2.vm.network "forwarded_port", guest: 80, host: 8878
vagrant2.vm.network "forwarded_port", guest: 443, host: 7444
end
config.vm.define "vagrant3" do |vagrant3|
vagrant3.vm.box = "ubuntu/xenial64"
vagrant3.vm.network "forwarded_port", guest: 80, host: 8879
vagrant3.vm.network "forwarded_port", guest: 443, host: 7445
end
end
Also see Ansible/Vagrant.
Inventory file: hosts
Info for the inventory file (port numbers) can be obtained with:
vagrant ssh-config
The corresponding inventory file looks like this:
hosts:
[servers] v1 ansible_host=127.0.0.1 ansible_port=2222 v2 ansible_host=127.0.0.1 ansible_port=2201 v3 ansible_host=127.0.0.1 ansible_port=2202
Playbook
Pre-Install Python 2
We need to make sure that Python 2 is installed so that Ansible can do its thing and use the various modules.
Unfortunately, on Ubuntu Xenial, Python 2 is not available by default, so we need to shim it in before we do anything else.
The playbook needs to have a pre task, which we set up as follows:
$ cat provision.yml
---
#
- name: provision the yeti worker nodes and prepare them for Ansible
hosts: servers
gather_facts: no
pre_tasks:
- name: install python2
raw: sudo apt-get -y install python
Now we can apply this playbook to each of the nodes:
$ ansible-playbook -i hosts provision.yml
_______________________________________________
< PLAY [provision the yeti worker nodes and prepare them for Ansible] >
-----------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
________________________
< TASK [install python2] >
------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
changed: [v2]
changed: [v3]
changed: [v1]
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
v1 : ok=1 changed=1 unreachable=0 failed=0
v2 : ok=1 changed=1 unreachable=0 failed=0
v3 : ok=1 changed=1 unreachable=0 failed=0