Giter Club home page Giter Club logo

personal-ansible's Introduction

personal-ansible

Ansible playbook(s) for personal servers. They automate my (not terribly unique) routine for setting up a new Ubuntu server:

  1. common role: apply basic security hardening
  2. mysql role: install and secure mysql
  3. Uses roles imported from galaxy for configuring Apache and PHP (see Setup below)
  4. websites role: Set up and enable individual sites in Apache
  5. certbot role: Install the EFF Certbot client (aka letsencrypt) and enable individual SSL certificates for all websites

I’m also making use of ansible-vault for keeping server credentials secure while still including them in the repo.

Usage

Ensure workstation and VMs are configured according to ‘Setup’ (below).

When running against VMs for the first time:

ansible-playbook site-initonce.yml -e "ansible_port=22" --ask-vault-pass

To run against a single VM for the first time (note ending comma)

ansible-playbook site-initonce.yml -i "machine1," -e "ansible_port=22" --ask-vault-pass

Because this will disable root and password use in ssh as well change the ssh port, you should only be able to (and only need to) use this once.

For all subsequent runs to the same server(s):

# ansible-playbook site.yml --ask-vault-pass

To test without actually performing any changes, use the -C flag.

Shortcut script

Because all of that is a bit annoying to type, I’ve created a basic bash script ap to make it simpler.

Usage: ap [-c] [-i] [-h host1,host2]" [-p playbook.yml]

  -c        Runs ansible-playbook in Check mode (-C)
  -i        Initialize (use site-initonce.yml w/port 22 and root login)
  -p file   Specify a playbook (can be overridden if followed by -i)
  -h hosts  Limit to specified hosts (comma-separated)

Example usage:

./ap -i                # Runs site-initonce.yml with port 22
./ap -i -h host1       #  -- same as above, limit to one host
./ap                   # Runs site.yml
./ap -h host1,host2    #  -- same as above, limit to two hosts

./ap -p web.yml        # Specifies a playbook
./ap -c                # Runs ansible in Check mode (-C)
./ap -ci -h host1      # Check mode, init playbook...you get the idea

Setup

Virtual Machines

These playbooks assume:

  • Ubuntu 14.04 LTS
  • Passwordless login via public key is already configured for root. (Most cloud providers will allow you to select public keys to be added to root when you provision the VM.)

Local Environment (OS X)

  1. Install ansible: brew install ansible

  2. Install roles from galaxy (these get put into /usr/local/etc/ansible): # ansible-galaxy install -r galaxy-roles.yml

  3. Ensure ~/.ssh/id_rsa.pub exists (generate if not)

  4. Create the inventory of your servers:

    • mkdir -p /usr/local/etc/ansible
    • Create /usr/local/etc/ansible/hosts and add your servers (instructions)
    • You may wish to ln -s /usr/local/etc/ansible/hosts ./inv for convenient editing of the inventory
  5. Edit vars files under group_vars/all to match your setup

  6. Set variables for passwords, port numbers, etc. with ansible-vault edit group_vars/all/secret.yml

    • Password vars with a _PLAIN suffix are the plain text of the password; other password vars are hashes of the password. You will need to generate these hashes using one of these methods.
    • If anyone besides me uses this, you will need to replace group_vars/all/secret.yml with your own Ansible vault. Just make sure it includes all the vars with the vault_ prefix referenced in group_vars/all/vars.yml.
    • You should have an Ansible vault password stored in your password manager (1Password, KeePass, etc).

Files

Folders or files Description
ap Shortcut script for using ansible-playbook without having to type out all the options (see above)
galaxy-roles.yml Roles to install from galaxy
site-initonce.yml Playbook for new VMs (root login)
site.yml Playbook for all servers
webservers.yml Playbook for web servers
group_vars/all/*.yml These vars are automatically loaded for all playbooks
roles/ Any main.yml files are added to specific parts of the play (tasks, handlers, etc) automatically for that role. Any files under role/x/files/ can be referenced without specifying a path. (more info)

Planned Improvements

  • PHP and PHP-FM
  • Logrotate

personal-ansible's People

Contributors

otherjoel avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.