GithubHelp home page GithubHelp logo

ansible_playbooks's Introduction

ansible playbooks

how to use

Prep

  1. Create a hosts inventory file with your server hostname if you don't have one. For this example, we've created ~/ansible/hosts and the contents of the file is shown below. The name that goes inside of the square brackets is what ansible will look for when you refer to a host by name. The line below the square brackets is what you name your host inside of your ~/.ssh/config file.
[hostname_recognized_by_ansible]
name_that_you_use_inside_of_your_ssh_config_file
  1. add environment variable to your .bashrc file: export ANSIBLE_HOSTS=~/ansible/hosts. For more info on how to configure your hosts inventory, see this: https://valdhaus.co/writings/ansible-post-install/

  2. copy the role subdirectory of this repo inside of your ~/ansible directory. Your ~/ansible directory should now contain a hosts file and a roles subdirectory.

using roles

  1. create an run.yml file inside of your ~/ansible directory.

  2. A role is called inside of a playbook and the playbook is run. As a example, we will call the create_new_user role inside of the run.yml playbook. Your run.yml should look the same as below.

---
- hosts: hostname_recognized_by_ansible
  remote_user: login_user
  sudo: true
  vars:
    default_user: login_user
    new_user: deploy
  roles:
    - create_new_user
  1. The content that follows the hosts: label is the hostname you used inside of your hosts inventory file. The remote_user: is the user you will ssh into your instance with. sudo: is true because you need sudo privilege to create a new user. vars: are the variables that are needed inside of the role, for this case, default_user: is the user we use to ssh in and new_user: is the name of the user we wish to create. roles: is the role we wish to include in this play.

  2. Run the run.yml playbook by typing in ansible-playbook run.yml on your command line.

  3. To include multiple roles inside of your playbook, configure your run.yml to what is shown below.

---
- hosts: hostname_recognized_by_ansible
  remote_user: login_user
  sudo: true
  vars:
    default_user: login_user
    new_user: deploy
  roles:
    - create_new_user

- hosts: hostname_recognized_by_ansible
  remote_user: deploy
  sudo: true
  roles:
    - install_dependencies

- hosts: hostname_recognized_by_ansible
  remote_user: deploy
  sudo: false
  roles:
    - install_ruby_rvm

- hosts: hostname_recognized_by_ansible
  remote_user: deploy
  sudo: true
  vars:
    user: deploy
    password: password
    app_db: app_db
  roles:
    - install_postgresql

- hosts: hostname_recognized_by_ansible
  remote_user: deploy
  sudo: true
  roles:
    - install_nginx

- hosts: hostname_recognized_by_ansible
  remote_user: deploy
  sudo: true
  roles:
    - install_rails_dependencies

ansible_playbooks's People

Contributors

chickenriceplatter avatar

Watchers

 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.