yanehi / ansible-role-template

Template project for new Ansible roles.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

ansible-role-template

Template for custom Ansible roles.

Technical Requirements

Pre-requirements for Linux

  • install ansible
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get install ansible
  • check if python > v2 is installed
python --version
  • install vagrant for local vm provisioning
sudo apt-get install virtualbox
sudo apt-get install vagrant
  • install vagrant cachier plugin
vagrant plugin install vagrant-cachier

Ansible files and folder structure

  • ansible folder strucutre
site.yml                  # master playbook
servers.yml               # enable specific roles for hosts
ansible-role-template/    # this hierarchy represents a "role"
    /defaults             # define variables for usage in tasks 
    /handlers             # define "handlers" for start, stop and reload processes
    /meta                 # some metadata for the ansible galaxy
    /molecule             # molecule testing in tavis-ci
    /tasks                # tasks that will be executed on the servers
  • order of file execution

    • site.yml
    • dbservers.yml (based on hosts)
    • tasks
      • main.yml
        • sample_playbooks.yml
    • handlers
      • main.yml

Running playbooks

  • clone repo and configure your hosts
git clone git@github.com:yanehi/ansible-role-template.git
cd ansible-role-template
  • start virtual machine with centos7
vagrant up
  • copy the ssh-key from the ansible host to the required hosts

    • cat ~/.ssh/id_rsa.pub
  • on the hosts

    • mkdir ~/.ssh
    • touch ~/.ssh/authorized_keys && chmod 600 authorized_keys
    • copy your ansible hosts ssh-key to the authorized_keys file on each host
  • check the connection form the ansible host to the other hosts

    • ansible -m ping all
  • execute your ansible playbook

    • ansible-playbook <path to folder with role>/site.yml

Local linter

  • before pushing to travis-ci run yamllint and ansible-lint locally over your ansible role
  • requirements:
    • currently working only with linux
    • yamllint and ansible-lint are installed
./local_role_linter.sh <path to local ansible role repository>

About

Template project for new Ansible roles.

License:MIT License


Languages

Language:Shell 100.0%