LoginSignup
1
1

More than 5 years have passed since last update.

さんま祭りとansible

Posted at

今日は楽しみにしていた近所で行う"さんま祭り"が、

雨なので、台風なので、中止と言うことで残念。。

さんま1000匹が焼き焼きされるという、さんまにとっては恐ろしい祭り。

子供は雨なので公文をやらされてるので、私もテレビをつける訳にもいかず、ansibleでもやってみた。
そんな日曜日の朝;

まずはテストサーバーを2台仮想マシンcentos6.5で構築。

ansibleはプッシュ型なので鍵を配置してサーバーからクライアントにツーツーにしてあげる。

EPELからyumで入れれるっぽいので手っ取り早くそれで


rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel.repo
yum --enablerepo=epel update epel-release
yum --enablerepo=epel install ansible

バージョンは最新の1.7のようだ。


[root@ansiblesvr ansible]# ansible --version
ansible 1.7


[root@ansiblesvr ansible]# python --version
Python 2.6.6

●pingしてみる

無事はいったので疎通OKなノードへpingしてみる
えっと、構成を書いてなかった。
ansiblesvr
ansibleclient
名前の通りです。

ansiblesvrから以下でpingを打てるらしい。が失敗。


[root@ansiblesvr ansible]# ansible ansibletest -m ping
No hosts matched

対象ホストの定義が"inventory file"ってので必要のようです。

これがテンプレートのようですね。


[root@ansiblesvr ansible]# head -25 /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

green.example.com
blue.example.com
192.168.100.1
192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

[webservers]
alpha.example.org
beta.example.org
192.168.1.100
192.168.1.110

今回は必要なものだけ書いて試してみます。


[root@ansiblesvr ansible]# cat /etc/ansible/hosts
[testwebserver]
ansibleclient
192.168.1.2

ピング


[root@ansiblesvr ansible]# ansible ansibleclient -m ping
ansibleclient | success >> {
"changed": false,
"ping": "pong"
}

ピンポン!
OKそう

任意のコマンドもOK


[root@ansiblesvr ansible]# ansible ansibleclient -a 'cat /etc/redhat-release'
ansibleclient | success | rc=0 >>
CentOS release 6.5 (Final)

コマンド実行も一元的に複数サーバーにOKってことですね。

▲学び:対象ホストはinventory file(/etc/ansible/hosts)に書くと

●"play book"なるものが必要のようですが、とりあえずトライアンドエラー派なので一発試してみたら
apache入りましたねw
既存であるんでしょうね。play bookにapacheが。


[root@ansiblesvr ansible]# ansible ansibleclient -m yum -s -a name=httpd
ansibleclient | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: www.ftp.ne.jp\n * extras: www.ftp.ne.jp\n * updates: ftp.tsukuba.wide.ad.jp\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-31.el6.centos will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.2.15-31.el6.centos updates 824 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package(s)\n\nTotal download size: 824 k\nInstalled size: 2.9 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Installing : httpd-2.2.15-31.el6.centos.x86_64 1/1 \n\r Verifying : httpd-2.2.15-31.el6.centos.x86_64 1/1 \n\nInstalled:\n httpd.x86_64 0:2.2.15-31.el6.centos \n\nComplete!\n"
]
}

[root@ansibleclient ~]# /etc/init.d/httpd status

httpd は停止しています


[root@ansibleclient ~]# tail /var/log/yum.log
Aug 31 16:25:04 Installed: ack-2.12-2.el6.noarch
Aug 31 16:29:51 Installed: python-psutil-0.6.1-1.el6.x86_64
Aug 31 16:29:51 Installed: python-setuptools-0.6.10-3.el6.noarch
Aug 31 16:29:51 Installed: glances-1.7.4-1.el6.noarch
Oct 05 11:05:42 Installed: yum-utils-1.1.30-17.el6_5.noarch
Oct 05 11:05:46 Installed: httpd-2.2.15-31.el6.centos.x86_64

まだ、序章だけどここまでは何もはまらず
あとはplay bookでいろいろ書いて試してよさげならよさそうな。
ママからお買い物に行くよと言われたので、行ってきます><
結局1時間くらいしかやれなかった。また続きやります。

●ホスト情報取得

ansible test -m setup

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1