[CENTOS] Road to the Wizard: 7th Step

Ansible

I like Ruby. However, I am blindly believing because it was written in How to become a hacker that Python should be used. So I will go to Chef-> Ansible as an environment construction tool.

I have prepared a number of execution environments in Vagrant, so I will set it up immediately.

Difficulty ahead Epel does not work well ...

I tried to download Epel with the wget command, and now I can run it with rpm! (Easy victory) I thought, and typed sudo yum install ansible, but for some reason I got an error and it didn't work. sudo yum -y update also stopped working Why (´ ・ ω ・ `)?

I can't help it, so I'm sorry but I decided to kick it out ...

Try different installation methods and succeed

sudo yum localinstall http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm -y

I happened to find this command on the site I found, so I executed the code above and successfully downloaded Epel!

With the same momentum sudo yum install ansible -y As a result of executing, the installation of Ansible was successful.

Authenticate the key

If you proceed with reference to Mr. Dotinstall's class, the next step will be key authentication. To authenticate the key, you must enter ssh-keygen -t rsa on the host side to issue a public key. Then create a .ssh / config file with vi and enter the information of the server to connect to. How to write

Host web HostName 192.168.33.12

Host db HostName 192.168.33.13

Write like this. Key authentication and host settings are now perfect

The next one is ansible!

Ansible

The first thing you have to do is to write the connection destination information in a file called host. It will be like this.

[web] 192.168.33.12

[db] 192.168.33.13

The name and IP address of the web and db will now match. By the way, if you write all, it will be all.

... can this be grouped? Let's find out later

I will try to ping these two. The command is like this!

ansible all -i hosts -m ping

Playbook and ansible.cfg

It's finally time to run the ansible command, which is even more convenient. There will be no direct command to use more advanced functions

The file name that describes instructions like chef is playbook.yml. So, what's the preparation before writing it in playbook.yml? It seems that you need something called ansible.cfg.

However, it seems that there are only two lines to write. [defaults] hostfile= ./hosts

only this...

short!

By reading this in playbook.yml, it seems that you can flexibly describe what kind of command is issued to which server. Like a clutch on a mission car

Load this in playbook.yml.

playbook.yml is a natural yaml file --- Start writing with.

Then indicate which server you want to support.

This time web,db Since we have prepared two, the options that the playbook can take are There are three, all, web, and db.

If you want to support all, it will be like this. - hosts: all

For commands that require administrator privileges sudo: yes It seems that the task is nested and described.

I immediately put in httpd.

By the way, when executing the ansible command using the playbook, the description of the execution command changes a little. ansible-playbook playbook.yml It changes to.

And a few minutes to wait.

Finally httpd was installed with yum! !! !!

Apache page does not appear ....

I finally finished installing Apache, but when I access it with chrome, the page cannot be displayed ...

Why (´ ・ ω ・ `)?

A few minutes to worry

I came up with the idea of stopping iptables and described the contents to stop iptables in the playbook

When I accessed it again, I saw it safely! !! !! !!

(´∀`)

Impressions of Ansible

It's simpler and easier to write than chef. Since chef was a tool that required Ruby commands, ansible thought that python was required, but in reality, I never wrote python. If anything, it's just a description of yaml. After that, I managed to do something just by looking at the official document, so I don't hate it without eating it. It's too convenient and I should have done it earlier (´ ・ ω ・ `)

The site I referred to this time is Dotinstall Teacher

And official page of ansible

It was (* ´∀ ` *)

Recommended Posts

Road to the Wizard: 4th Step
Road to the Wizard: 7th Step
Road to the Wizard: Step 8 (Interpret How to become a Hacker)
The road to Pythonista
The road to Djangoist
The road to download Matplotlib
Today's AtCoder ~ The Road to the Brown Coder ~
The first step to getting Blender available from Python
Road to LPIC-1 acquisition
The first step to creating a serverless application with Zappa
[Python] The first step to making a game with Pyxel
A road to intermediate Python
Dot according to the image
[Introduction to cx_Oracle] (8th) cx_Oracle 8.0 release
How to increase the axis
How to start the program
The road to installing Python and Flask on an offline PC
The road to web application development is a long way off
The 14th offline real-time how to write reference problem in python
The 18th offline real-time how to write reference problem in Python