DEV Community

Cover image for Learn Ansible for beginner
Daniel Pepuho
Daniel Pepuho

Posted on • Updated on

Learn Ansible for beginner

#day01

πŸ‘‹ Hi there, this is my documentation when i learning about Ansible

What is Ansible?

Ansible is an open source tool that is most used by a SysAdmin in the process of automating.

Why you should use Ansible?

Ansible is a powerful tool that you can use in the process of server management, configuration task, and other tasks. So when you use Ansible, many process such as configuration or deployment an application in server will be simple and quickly. πŸ‘Š

BTW, you don't need to install Ansible on the remote hosts. You just need SSH and Python 2 or later with the Python simplejson library installed

Let's start!!

Setup

Setup

  • Server side

1.Configure Network
2.Configure sudo passwordless
3.Configure SSH passwordless

  • Controller

install ansible in your laptop or PC.

Linux:

$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update  ppa:ansible/ansible
$ sudo apt install ansible
Enter fullscreen mode Exit fullscreen mode

MacOS:

$ brew install ansible
Enter fullscreen mode Exit fullscreen mode

Okay, after installation we should make new user.

$ adduser user1
Enter fullscreen mode Exit fullscreen mode

then enable passwordless sudo to this user by go to bottom line and type this:

$ sudo visudo

# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d

user1 ALL=(ALL:ALL) ALL
Enter fullscreen mode Exit fullscreen mode

then make a new directory

$ mkdir ansible-demo

$ cd ansible-demo
Enter fullscreen mode Exit fullscreen mode

after that, let's make new file with name ansible.cfg, the ansible.cfg is a brain for Ansible. Add many lines to initials an inventory

$ nano ansible.cfg
...
[defaults]
inventory = hosts # initials new file as inventory

Enter fullscreen mode Exit fullscreen mode

save it and then add new file again with name hosts as an inventory file

$ nano hosts
...
[ubuntu]
srv1 ansible_user=ansible

[debian]
srv2 ansible_user=ansible
Enter fullscreen mode Exit fullscreen mode

So..now your working directory look like this

/ansible-demo(main*) Β» $ tree       
.
β”œβ”€β”€ ansible.cfg
└── hosts
Enter fullscreen mode Exit fullscreen mode

NB:

  • ansible.cfg: his is the brain and the heart of Ansible, the file that governs the behavior of all interactions performed by the control node. "Redhat"
  • hosts: as inventory so with 'hosts' you can managed multiple nodes at the same time.

i forgot a thing, so you also make customize at
/etc/hosts .

$ nano /etc/hosts

127.0.0.1       localhost
172.16.238.20   srv1
172.16.238.10   srv2
Enter fullscreen mode Exit fullscreen mode

with this configuration makes it easier for you to do ssh with initials without using ip adddress.

$ ssh ansible@srv1
Enter fullscreen mode Exit fullscreen mode

coming soon

Top comments (0)