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!
** 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
This time, I will make something that outputs Hello World using localHost (self). I think you can understand the basics of Ansible with this.
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.
inventory
[target]
localhost
playbook.yml
---
- hosts: all
tasks:
- name: Hello World!
debug:
msg: "Hello World!"
Please note that indentation is important for YAML format files.
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