Who am I?

Office of Technology

Zuul

Ansible

Who am I?

Technical Committee

Developer Infrastructure Core Team

Former Foundation Board of Directors

PTL of shade project

Ansible

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

Why Ansible is Great

Ansible Overview

Ansible Simple Example

simple.yaml


- hosts: all
  tasks:
  - name: Print hostname of server
    command: hostname
      

A playbook containing a play that will run against all hosts in the inventory. It has one task that uses the command module to run the "hostname" command.

Ansible Longer Example

longer.yaml


- hosts: git
  roles:
    - create-mirror-locations
- hosts: code-review.example.com
  roles:
    - create-repositories
      

A playboook containing two plays. The first runs a role called "create-mirror-locations" against a group of hosts from the inventory called "git". Then it runs a role called "create-repositories" against a host from the inventory called "code-review.example.com".

Ansible Modules

Ansible OpenStack Modules

Interop - Work on All OpenStack Clouds

Don't let the existence of Rackspace modules confuse you. The OpenStack modules work just great on Rackspace

Work Around Deployer Differences ... To a Point

A provider decided to redefine the OpenStack Availability Zone concept complete with incompatible API changes. That is unsupportable.

PS. Don't do that

Based on shade library

Integration Testing

Let's Take a Few Steps Back

OpenStack in Ansible and Multi-cloud Operations are easy...

but you need to know a few things.

Module Structure

OpenStack Dynamic Inventory Script

New inventory plugin coming in Ansible 2.4

Modules for All OpenStack Resources are Welcome Upstream

To Serve All Users, We Have to be Strict

clouds.yaml

What about Mac and Windows?

USER_CONFIG_DIR is different on Linux, OSX and Windows.

SITE_CONFIG_DIR is different on Linux, OSX and Windows.

Config Terminology

For multi-cloud, think of two types:

Remember your Execution Context!

basic clouds.yaml for the example code

Simple example of a clouds.yaml


clouds:
  my-citycloud:
    profile: citycloud
    auth:
      username: mordred
      project_id: 65222a4d09ea4c68934fa1028c77f394
      user_domain_id: d0919bd5e8d74e49adf0e145807ffc38
      project_domain_id: d0919bd5e8d74e49adf0e145807ffc38
      

Where's the password?

secure.yaml

Example secure.yaml


clouds:
  my-citycloud:
    auth:
      password: XXXXXXXX
      

more clouds.yaml

More information can be provided.


my-vexxhost:
  identity_api_version: 3
  image_endpoint_override: https://image-ca-ymq-1.vexxhost.net/v2
  profile: vexxhost
  auth:
    user_domain_id: default
    project_domain_id: default
    project_name: d8af8a8f-a573-48e6-898a-af333b970a2d
    username: 0b8c435b-cc4d-4e05-8a47-a2ada0539af1
      

Much more complex clouds.yaml example


my-internap:
  auth:
    auth_url: https://identity.api.cloud.iweb.com
    username: api-55f9a00fb2619
    project_name: inap-17037
  identity_api_version: 3
  floating_ip_source: None
  regions:
  - name: ams01
    values:
      networks:
      - name: inap-17037-WAN1654
        routes_externally: true
        default_interface: true
      - name: inap-17037-LAN3631
        routes_externally: false

Extra Variables to Control Inventory Behavior

ansible:
  use_hostnames: False
  expand_hostvars: True
  fail_on_errors: True

Test Your Config

---
- hosts: localhost
  tasks:
  - os_auth:
      cloud: "{{ item.cloud }}"
      region_name: "{{ item.region }}"
    with_items:
    - cloud: my-vexxhost
      region: ca-ymq-1
    - cloud: my-citycloud
      region: Buf1
    - cloud: my-internap
      region: ams01
      

More Interesting


- hosts: localhost
  tasks:
  - os_server:
      name: "my-server"
      cloud: "{{ item.cloud }}"
      region_name: "{{ item.region }}"
      image: "{{ item.image }}"
      flavor: "{{ item.flavor }}"
      auto_ip: true
    with_items:
    - cloud: my-vexxhost
      region: ca-ymq-1
      image: Ubuntu 16.04.1 LTS [2017-03-03]
      flavor: v1-standard-4
    - cloud: my-citycloud
      region: Buf1
      image: Ubuntu 16.04 Xenial Xerus
      flavor: 4C-4GB-100GB
    - cloud: my-internap
      region: ams01
      image: Ubuntu 16.04 LTS (Xenial Xerus)
      flavor: A1.4

Check That There is an Inventory

python ~/src/github.com/ansible/ansible/contrib/inventory/openstack.py --list

Cleanup After Ourselves


- hosts: localhost
  tasks:
  - os_server:
      cloud: "{{ item.cloud }}"
      region_name: "{{ item.region }}"
      name: my-server
      state: absent
    with_items:
    - cloud: my-vexxhost
      region: ca-ymq-1
    - cloud: my-citycloud
      region: Buf1
    - cloud: my-internap
      region: ams01
      

Check out Ansible Cloud Launcher

https://git.openstack.org/cgit/openstack/ansible-role-cloud-launcher

Check out Linch-pin

http://linch-pin.readthedocs.io/en/develop/

Linch-pin provides a collection of Ansible playbooks for provisioning, decommissioning, and managing resources across multiple infrastructures. The main goal of linch-pin is to facilitate provisioning and orchestration of resources in a multi-cloud environment through a topology file.