Complete Computing Environment: Server Orchestration with Ansible

Table of Contents

(provide 'cce-ansible)

Orchestration using Ansible

All of my primary personal infrastructure is handled using Ansible1, a fantastic server orchestration tool. My workflow is a bit mungy, there's a lot of technical debt that I've been carrying since version… 0.8 of Ansible?

Long term plan is to rewrite my Ansible playbooks from scratch but in the meantime I have a mess of about 70 git submodules to manage each piece of infrastructure. My environment needs to support Ansible's YAML format as a first-class citizen, and should have good autocomplete and snippets for common Ansible modules. As an added bonus, ansible has wonderful manual documentation and these should be easily accessible. Further, Ansible playbooks are run using a command line tool ansible-playbook which I should be able to easily run from within my working environment.

In terms of actually working with Ansible, start out with setting up flymake-yaml to properly complain about the YAML errors that I get whenever I write Ansible.

(install-pkgs '(flymake-yaml))
(eval-after-load 'yaml-mode (lambda ()
                              (require 'flymake-yaml)
                              (add-hook 'yaml-mode-hook 'flymake-yaml-load)
                              (add-hook 'yaml-mode-hook (lambda () (variable-pitch-mode -1)))))

Core Technologies

  • Ansible
  • YAML
  • Git submodules

Core Requirements

  • Easy management of Git submodules
  • Arbitrary snippet expansion
  • Easy documentation referencing
  • Integration with the deployment tool itself
  • Cross-language jump-to-definition and search-for-usage patterns

A Hairbrained Idea: Literate Playbooks

I've been greenfielding a project lately, I'm not sure if it's a good idea, or if it'll even work, but bare with me for a moment: Literate Ansible Playbooks. I want to add an Org-babel language plugin with the following characteristics:

  • Define a language runner that will execute simple src-blocks using ansible-playbook
  • Will tangle a src-block out to a directory structure that can be run using ansible-playbook

I'm still working on exactly how this things work. I have an MVP providing the first half of it done, but nowhere near clean enough to release yet. I have other projects eating up my side-time bandwidth but I'd like to tackle this some day, if only so that I can render my infrastructure to LaTex and have a book bound.

This code block:

#+BEGIN_SRC ansible :name "Test Play" :hosts all :user rrix :sudo yes :connection local :type task :role install_emacs
- name: Ensure Emacs is installed
  yum:
    state: installed
    name: emacs-nox
#+END_SRC

would render in to:

- name: Test Play
  hosts: all
  user: rrix
  sudo: yes
  connection: local

  - name: Ensure Emacs is installed
    yum:
      state: installed
      name: emacs-nox

and then be executed by ansible-playbook.

And then, when you tangle, it would generate a tree:

install_emacs
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
└── vars
    └── main.yml

where tasks/main.yml would contain all of the tangled tasks, we could tangle jinja in to templates, etc.

Again, this is totally hairbrained, but I love the thought behind it and would love to explore it some time.

MVP Execute a single play using OB

Sessionization to biuld an entire playbook from a bunch of tasks

Tangle tasks in to a playbook

Tangle different object types

Tangle roles

Footnotes:

Author: Ryan Rix

Created: 2017-05-19 Fri 13:33

Validate XHTML 1.0