Introduction to Ansible Part 1'Hello World !!'

What is Ansible?

Overview

Called a configuration management tool The remote machine and server can be set automatically according to the program. Even if you do not repeat the same work and set up the server A convenient friend who will set up any number of units as long as you give Ansible the code. The test environment can be reproduced!

merit

  1. ** Idempotent **
    The same result is guaranteed no matter how many times you do it from the same program.
  2. ** Easy to understand **
    The main program is built on YAML and is really easy to understand and read.
  3. ** Agentless **
    Speaking of configuration management tools, there are various other services, but
    Many will not work without installing the software on remote hosts.
    However, Ansible does not have to do that, just an SSH connection and it works on its own!
  4. ** Any shell command can be executed on the remote server **
    You can easily implement shell commands in your program. Thank you.
    By the way, there are many modules available, which are convenient.
  5. ** Ready to use **
    There is little prior knowledge required to be able to use it.
    Why not write a command in the playbook?
    And the remote host is specified like this. I feel like I can start with.

Regarding Ansible installation

** Mac users ** are really comfortable. Search for ʻAnsible installation. ** Windows users ** are a little hard. I also struggled. I'm only struggling anymore. If you have a virtual environment, it may not be a problem, but I started by launching it on a docker container. By the way, recently I am using the one launched on ec2. If you search for docker Ansible or ʻaws Ansible, you will find various results. [By the way, the article I referred to] Docker edition [Ansible] Ansible hands-on with Docker AWS edition [Introduction to Ansible] Let's run Ansible in EC2 environment

Try to output "Hello World"

This time, I will make something that outputs Hello World using localHost (self). I think you can understand the basics of Ansible with this.

Required files

file organization

helloworld
├── playbook.yml
└── inventory

playbook.yml Setting management script in Ansible. Basically, I spend my time writing this while using Ansible. Simply put, write the instructions you want the server to do. inventory A file that describes which remote host is targeted. INI format.

Contents of inventory

inventory

[target]
localhost

Contents of playbook

playbook.yml

---
- hosts: all
  tasks:
    - name: Hello World!
      debug:
        msg: "Hello World!"

Please note that indentation is important for YAML format files.

Try to run

localhost

$ ansible-playbook -i inventory playbook.yml
PLAY [all] **********************************************************

TASK [Gathering Facts] **********************************************
ok: [localhost]

TASK [helloworld : Hello World!] ************************************
ok: [localhost] => {
    "msg": "Hello World!"
}

PLAY RECAP **********************************************************
localhost              : ok=2    changed=0    unreachable=0    failed=0   

If you execute it like this, the execution result will come out suddenly. With this, Ansible works for the time being. Easy and convenient.

Related Documents Introduction to Ansible Part 2'Basic Grammar' [Introduction to Ansible Part ③'Inventory'] (https://qiita.com/nouhautayomi/items/d647ec7ad0fa7ea3b51f)
** References ** First Ansible (written by Lorin Hochstein, translated by Ryuji Tamagawa, O'Reilly Japan Co., Ltd.) People inside will teach you what you can do with Ansible

Recommended Posts

Introduction to Ansible Part 1'Hello World !!'
Introduction to Ansible Part ③'Inventory'
Introduction to Ansible Part ④'Variable'
Introduction to Ansible Part 2'Basic Grammar'
Introduction to TensorFlow --Hello World Edition
Introduction to PyQt4 Part 1
Introduction to Python Hands On Part 1
Hello world
How to build Hello, World on #Nix
Web-WF Python Tornado Part 3 (Introduction to Openpyexcel)
Kaggle: Introduction to Manual Feature Engineering Part 1
Introduction to MQTT (Introduction)
Introduction to Scrapy (1)
Introduction to Scrapy (3)
Introduction to Supervisor
Introduction to Scrapy (2)
C language to see and remember Part 1 Call C language from Python (hello world)
[Linux] Introduction to Linux
cython hello world
Introduction to discord.py
From Kivy environment construction to displaying Hello World
[Introduction to cx_Oracle] (Part 3) Basics of Table Reference
Say hello to the world with Python with IntelliJ
[Introduction to cx_Oracle] (Part 7) Handling of bind variables
To myself as a Django beginner (3)-Hello world! ---
web2py memo: Hello World
[Programming learning] Logic comparison by language part.1 ("Hello World")
Introduction to Lightning pytorch
Introduction to Web Scraping
hello world with ctypes
Introduction to EV3 / MicroPython
RabbitMQ Tutorial 1 ("Hello World!")
Introduction to Python language
Introduction to TensorFlow-Image Recognition
RaspberryPi3 (STRETCH) setup from OS installation to Hello World
Introduction to OpenCV (python)-(2)
Hello, World with Docker
[Introduction to cx_Oracle] (Part 11) Basics of PL / SQL Execution
Introduction to Dependency Injection
Introduction to Private Chainer
Django's first Hello World
Hello world with flask
[Introduction to cx_Oracle] (Part 13) Connection using connection pool (client side)
Introduction to Python numpy pandas matplotlib (~ towards B3 ~ part2)
Introduction to machine learning
[Introduction to cx_Oracle] (Part 6) DB and Python data type mapping
[Introduction to cx_Oracle] (Part 4) Fetch and scroll of result set
An introduction to Python that even monkeys can understand (Part 3)
From setting up a Rust environment to running Hello World
Introduction to Python scikit-learn, matplotlib, single-layer algorithm (~ towards B3 ~ part3)
An introduction to Python that even monkeys can understand (Part 1)
Introduction to Socket API Learned in C Part 2 Client Edition
AOJ Introduction to Programming Topic # 1, Topic # 2, Topic # 3, Topic # 4
Introduction to electronic paper modules
A quick introduction to pytest-mock
Introduction to dictionary lookup algorithm
Introduction to Monte Carlo Method
[Learning memorandum] Introduction to vim
Introduction to PyTorch (1) Automatic differentiation
opencv-python Introduction to image processing
Introduction to Python Django (2) Win