Code Monkey home page Code Monkey logo

ansible.resources's Introduction

Ansible Resources

Learn how to automate Raspberry Pi setup with Ansible. The Raspberry Pi is a tiny and affordable computer that you can use to learn, test and experiment concepts about distributed computing. The first challenge is always how to keep the Rasbperry Pi’s up to date. Having four Rasbperry Pi seems manageable, but If you have more than 4 Rasbperry Pi, you'll need an automation tool like Ansible to automate repetitive task like installing, updating software on your Rasbperry Pi’s.

In this brief tutorial, I'll walk you through the basics of Ansible using a cluster of four Raspberry Pi.

alt text

 

Table of contents

top  

Installing Ansible on Mac

The best way to get started on a macOS is to use Homebrew. If you already have Homebrew installed, you can install ansible by running the following command

brew install ansible

If you don't already have Homebrew installed, I would strongly recommend that you install it! It's incredibly useful for installing software dependencies like OpenSSL, MySQL, Postgres, Redis, SQLite, and more.

You can install it by running the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

top  

Test Ansible

Run the following command:

ansible localhost -m ping
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

top  

Edit your macOS /etc/hosts for Ansible

  1. Open your terminal, type this command:
sudo nano /etc/hosts
  1. Add 192.168.1.x to end of the /etc/hosts file.
# Raspberry Pi
192.168.1.6		raspi1    
192.168.1.7		raspi2
192.168.1.8		raspi3
192.168.1.9		raspi4
  1. To save your changes, press Ctrl+x on your keyboard.

top  

Enable Passwordless SSH access for ansible

In order to fully control a remote machine we need to be able to execute command on the remote machines as user root.

To enable passwordless sudo:

  1. Log in to the Raspberry Pi command-line interface. The default user name and password of the Raspberry Pi hardware are pi and raspberry, respectively.

  2. In the command-line interface, type this command:

sudo nano /etc/sudoers.d/010_pi-nopasswd
  1. Enable passwordless sudo access by adding this line:
<user name> ALL=(ALL) NOPASSWD: ALL

For example, to provide passwordless sudo access to a user pi, type:

pi ALL=(ALL) NOPASSWD: ALL
  1. To save your changes, press Ctrl+x on your keyboard.

  2. For these changes to take effect, restart Raspberry Pi by typing this command:

sudo reboot

top  

Ansible Hosts and Groups

  1. Open your terminal, type this command create /etc/ansible/hosts directory
sudo mkdir -p /etc/ansible
  1. Add hostname to /etc/ansible/hosts file.
[gui]
raspi1 
raspi2 

[nogui]
raspi3 
raspi4 

You also can define ‘host list’ with ranges

[gui]
raspi[1:2]

[nogui]
raspi[3:4]

top  

Ansible playbook to ping all server
ansible -m ping all
raspi2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
raspi1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
raspi4 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
raspi3 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

top  

Check python version with ansible
ansible -m shell -a 'python -V' gui

raspi1 | CHANGED | rc=0 >>
Python 2.7.13

raspi2 | CHANGED | rc=0 >>
Python 2.7.13
ansible -m shell -a 'python -V' all

raspi3 | CHANGED | rc=0 >>
Python 2.7.13

raspi4 | CHANGED | rc=0 >>
Python 2.7.13

raspi1 | CHANGED | rc=0 >>
Python 2.7.13

raspi2 | CHANGED | rc=0 >>
Python 2.7.13

top  

ansible.resources's People

Contributors

sayems avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

lreddy563

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.