Ansible 101 Notes: Episode 1 - Introduction to Ansible

Ansible 101 - Episode 1 - Introduction to Ansible

CHAPTER 1

Buy Ansible for DevOps: https://www.ansiblefordevops.com (recommend LeanPub for CI)

"Enders Game: The Ansible, was a device used for instantaneous communication across any distance."

See: https://github.com/geerlingguy/ansible-for-devops for examples and more!

See: Ansible Documentation & Ansible Blog

LINUX$ pip install ansible

WINDOWS> 

  • Also you'll need Windows Subsystem for Linux (WSL) installed (reboot required):
    • wsl --install
    • And from Ubuntu:
      • sudo apt-get update
      • sudo apt-get upgrade
      • sudo apt install python3-pip
      • pip install ansible
      • echo $PATH
      • export PATH="/home/myunixuser/.local/bin:$PATH"
      • # Edit ~/.profile with the PATH about to make it permanent
      • vi ~/.profile

LINUX$ ansible --version

All Ansible needs is a working SSH connection to the Linux server, and a version of Python (Ansible sends over a Python module.)

STEP 1) Create an inventory file so Ansible knows which servers to work on (example is the group).

[example]
1.2.3.4
myserver.domain.local

To let Ansible know about the inventory file, group, and ping test with user centos:

ansible -i inventory example -m ping -u centos

We can create ansible.cfg to override the defaults, for example:

[defaults]
INVENTORY = inventory

ansible example -m ping -u centos

Note: Search for Ansible configuration for other things you can add to ansible.cfg.

-m for module (default is the command module) -a is the arguments e.g (with default module so -m not required):

-a "free -h" (for free memory) / -a "date" (to check the date on the server)

CHAPTER 2 (31:58)

Tip: Check out Vagrant | HashiCorp Developer for creating development environments (VMs.)

A simple Ansible playbook that Vagrant can run: playbook.yml

---
- name: Set up NTP on all servers.

  hosts: all
  become: yes
  tasks:
    - name: Ensure NTP is installed.
      yum: name=ntp state=present
    - name: Ensure NTP is running.
      service: name=ntpd state=started enabled=yes

become = yes : means to become the root/sudo user
yum (the Ansible Yum module): Installs the package ntp, if state=present/absent/latest
service (the Ansible Service module)

Idempotent = If we make multiple identical requests and receive the same response every time, the APIs are generally called idempotent. Some API consumers knowingly or unknowingly make the same request twice or thrice. The APIs have to understand this and reply with the same response.

Comments