Ansible

Ansible mindmap

Get Started. It's Free
or sign up with your email address
Ansible by Mind Map: Ansible

1. Environment Setup

1.1. Type of machines: - Control machine: manages other machines - Remote machine: controlled by other machines

1.2. Multiple remote systems can be handled by one machine. - Remote machine managing is done by ansible by default - Ansible doesn;t leave any software running on them. Therefore there is no need of ad upgrade when moving to a newer version - Installing: $ sudo apt-get update $ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install ansible

2. YAML

2.1. YAML syntax is used to express ansible playbooks

2.2. Key-value pair: - Dictionary is represented in key value pair Ex: info: name: Cong Chi Nguyen github: chicongst age: 25 sex: male

2.3. Representing lists: - Each element has to be written in a new lint with "-" as the prefix Ex: countries: - Vietnam - Japan

2.4. Lists inside the dictionary: Ex: name: Cong Chi Nguyen age: 25 sex: male likes: - programing - english

3. Adhoc-Command

3.1. Check connectivity of hosts $ ansbile <group> -m ping

3.2. Rebooting hosts $ ansible <group> -a "/bin/reboot"

3.3. Check host system's info $ ansible <group> -m setup | less

3.4. Transfering files $ ansible <group> -m copy -a "src=/home/chicongst/data dest=/home/ubuntu/data"

3.5. Handle service: state: started, stopped, restarted $ ansible <group> -m service -a "name=nginx state="state"

3.6. ....

4. How does it works?

4.1. Connects nodes and pushes small programs called module to them and are removed when they are done.

4.2. The management node control whole execution of the playbook.

4.3. The inventory file provides the list of hosts where the modules need to be run.

4.4. The management node does an 'ssh' connection and executes the modules and install the software.

5. Playbook

5.1. It is the place where all YAML files are stored and executed. Acs like a to-do list

5.2. YAML: yet another markup language

5.3. A playbook can have more than one plays. Plays map the instructions defined against a particular host

5.4. Sample playbook/YAML file: --- - name: Install the nodejs apt: name: nodejs state: present

6. Trouble shooting

6.1. Common strategies to debug playbooks are: - Debug and register - Use verbosity ( verbosity level)

6.2. Playbook issues: - Quoting - Indentation

6.3. Some drawbacks are: - OS restrictions: is OS dependent so code on one OS will not work for anthother - Once playbook is running, adding of hosts is not possible error reporting is mediocre.

7. Variable

7.1. Same as using variables in programing languages Ex: - http_port:80 - Server is running on {{ http_port }}

7.2. Keywords used: - Block: ansible syntax to execute a block - Name: name of the block - Action: the code that is to be executed - Register: registers the output - Always: states that below word will be run - Msg: displays the message

7.3. Exception handling: - Similar to any other programing language - Keywords: rescue and always - The code is written in block - It goes to the rescue phase and gets executed if the command in the block fails - There by block is the same as "try block", catch block is like "rescue" and always performs the same function as we know.

8. Terms

8.1. Service/server: a process that provides service

8.2. Machine: physical machine, VM or a container

8.3. Target machine: end machine to be configured by Ansible

8.4. Task: an action

8.5. Playbook: location where YAML files are written and executed

9. Advantages of Ansible

9.1. - Free and opensource - System requirements - Developed in python - Lightweight and quick deployment - Large community base

10. What is Ansible?

10.1. Ansible is an open-source automation platform.

10.2. Ansible can help you with configuration management, application deployment, task automation...

10.3. Very simple to set up, efficient, and more powerful.