From charlesreid1

No edit summary
Line 55: Line 55:




==Directory Structure==


The basic directory structure we'll use with Ansible is:


<pre>
playbook/
    hosts/
        ...ansible inventory files...


    ...ansible files...
    ...vagrant files in .vagrant directory...
</pre>
==Using Ansible Locally with Vagrant==
[[Vagrant]] allows you to set up virtual machines using VirtualBox, and manage/set them up using Ansible.
See [[Vagrant]] page for how to get a Vagrant box set up, running, and listening for SSH connections.
From here, we can connect Ansible with Vagrant by telling Ansible about how to connect to the machines that Vagrant created.
To do this, we create an inventory file in


=Flags=
=Flags=

Revision as of 21:06, 4 November 2018

Notes

Ansible can be thought of as a for-loop over SSH scripts, but it's also much more than that.

Basic Features

Ansible config management scripts (playbooks) are in YAML. This is like executable documentation - kind of like a readme containing all the commands you would otherwise be running, all typed out, except instructions won't go out of date because they're actually being executed.

Ansible servers require SSH and Python.

Push Based

Ansible is push-based, which means the workflow looks like this:

  • You make a change to the playbook
  • You run the new playbook
  • Ansible connects to servers and executes modules, changing the server state

The ansible-playbook command is the gateway to connecting to the remote server.

The push-based approach means you control when things happen to the server, making scaling easier.

Scaling Down, Too

Ansible obeys Alan Kay’s maxim: “Simple things should be simple; complex things should be possible.”

Modules

Ansible allows you to execute arbitrary shell commands.

Ansible also offers more powerful feature: modules, which perform tasks like installing packages restarting services, or copying config files.

Modules are declarative: describe/declare the state you want the server to be in. Example: invoke the user module to ensure there is an account named "deploy" that is in the group "web"

user: name=deploy group=web

Ansible is idempotent - meaning, if the user already exists, it will do nothing. This makes it safe to run the Ansible script multiple times.

What You Should Know

List of things you should know how to do before getting started:

  • connect to remote machine via SSH
  • interact with bash command line shell (pipes and redirects)
  • install packages
  • use sudo command
  • check and set file permissions
  • start/stop services
  • set env vars
  • write scripts (any language)

Ansible also uses uses YAML and Jinja and is Python-based.


Directory Structure

The basic directory structure we'll use with Ansible is:

playbook/
    hosts/
        ...ansible inventory files...

    ...ansible files...

    ...vagrant files in .vagrant directory...

Using Ansible Locally with Vagrant

Vagrant allows you to set up virtual machines using VirtualBox, and manage/set them up using Ansible.

See Vagrant page for how to get a Vagrant box set up, running, and listening for SSH connections.

From here, we can connect Ansible with Vagrant by telling Ansible about how to connect to the machines that Vagrant created.

To do this, we create an inventory file in

Flags