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.
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 ...
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.
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
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! !! !!
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! !! !! !!
(´∀`)
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