# Intro to Ansible

---
# Agenda
* What is Ansible?
* Installing and using Ansible
* Live Demo
* Use cases in GiG
* Q&A
---
# What is Ansible?
----
An open source configuration management tool.
Ansible is able to easily manage the state of configuration of the infrastructure hosting our applications.
----
Ansible uses "Playbooks" as step by step instructions for the host to follow.
These playbooks are built with idempotency in mind, meaning whether we run them 1 or 1000 times, the end state of our servers always ends up the same.
----
Playbooks are essentially a piece of code we can commit to VCS;
This is thinking of infrastructure as code, and allows us to automate building, destroying and rebuilding of our application servers with consistency and limited human error.
---
## Technical details
* Agentless<!-- .element: class="fragment" data-fragment-index="1" -->
* Written in Python<!-- .element: class="fragment" data-fragment-index="2" -->
* Jinja Templates!<!-- .element: class="fragment" data-fragment-index="3" -->
* Uses YAML or INI format<!-- .element: class="fragment" data-fragment-index="4" -->
* Uses SSH or other implementations of it such as Paramiko<!-- .element: class="fragment" data-fragment-index="5" -->
---
## How does it work?
1. Ansible Connects to host via SSH<!-- .element: class="fragment" data-fragment-index="1" -->
2. Uploads ansible modules (written in Python)<!-- .element: class="fragment" data-fragment-index="2" -->
3. Executes said modules on the host.<!-- .element: class="fragment" data-fragment-index="3" -->
4. After all is said and done, the modules on the host are deleted.<!-- .element: class="fragment" data-fragment-index="4" -->
---
### Pros
* Easy to learn and to get started<!-- .element: class="fragment" data-fragment-index="1" -->
* [Batteries included](https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html)<!-- .element: class="fragment" data-fragment-index="1" -->
* Extensible<!-- .element: class="fragment" data-fragment-index="1" -->
* Reliable <!-- .element: class="fragment" data-fragment-index="1" -->
* Great documentation and supporting community<!-- .element: class="fragment" data-fragment-index="1" -->
----
### Cons
* Slow AF :turtle:<!-- .element: class="fragment" data-fragment-index="1" -->
* Doesn’t fail fast if there are config errors<!-- .element: class="fragment" data-fragment-index="1" -->
* Requires stable SSH connection <!-- .element: class="fragment" data-fragment-index="1" -->
---
# Installing ansible
`apt-get ansible`
`yum -y install ansible`
`pacman -s ansible`
`brew install ansible`
`# whatever windows users have to do`
---
# Using Ansible
## Inventory File
```
# staging_hosts example
[webservers]
staging.comply.gig.com
[workers]
staging-worker.comply.gig.com
staging-worker-02.comply.gig.com
staging-worker-03.comply.gig.com
[celery_match_images]
staging-worker-image.comply.gig.com
```
---
# Using Ansible
## Playbooks
```
# playbook1.yml
---
- hosts: webservers
tasks:
- name: Say Hello
debug:
msg: "Hello, World!"
```
---
# Live Demo
---
# Resources
* https://docs.ansible.com/
* https://www.ansiblefordevops.com/
* https://github.com/sk1u/ansible_demo
* https://rebelpenguin.atlassian.net/wiki/spaces/DEV/pages/636616705/Ansible+Best+Practices
* https://rebelpenguin.atlassian.net/wiki/spaces/AC/pages/463962113/Ansible
---

---
# Q&A
{"metaMigratedAt":"2023-06-14T21:54:56.518Z","metaMigratedFrom":"YAML","title":"Intro to Ansible","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"f7d5c28d-2ad8-4fb0-a3a1-cebdc1d99279\",\"add\":4904,\"del\":1275}]"}