From charlesreid1

Revision as of 07:48, 10 December 2018 by Admin (talk | contribs) (→‎Playbook)

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:

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:

$ cat 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

Provisioning 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