LoginSignup
17
16

More than 5 years have passed since last update.

AnsibleでCentOSにApache HTTP Serverをインストールしサービス開始を確認するところまで

Posted at

今回はタイトル通り、Ansibleを使ってCentOSにhttpdをインストールし、サービスが開始されるところまでを確認します。

環境

Location OS
Local Mac OS X
Remote CentOS 6.4 (VirtualBox/Vagrant)

Mac OS XでのAnsible環境構築に関しては、以下を参考にしています。
https://weluse.de/blog/installing-ansible-on-os-x.html

Playbook

今回はPlaybookのinclude機能を使っているため、YMLファイルが二つ、またhttpd動作確認時に必要となるHTMLファイル一つ、の構成です。

vagrant-httpd.yml
- hosts: vagrant
  port: 2222
  user: vagrant
  sudo: yes
  tasks:
    - include: centos/install-start-httpd.yml
centos/install-start-httpd.yml
    - name: install yum packages
      yum: name={{ item }} state=latest
      with_items:
      - httpd
      - python-setuptools
    - name: install easy_install package
      easy_install: name=pip
    - name: install pip package
      pip: name=httplib2
    - name: copy index.html
      copy: src=centos/index.html dest=/var/www/html
    - name: start httpd
      service: name=httpd enabled=yes state=started
    - name: check httpd is working
      uri: url=http://localhost/
centos/index.html
<html>
<head>
    <title>index.html</title>
</head>
<body>
    index.html
</body>
</html>

上記ファイルを配置し、事前にLocalからRemoteへSSH接続ができることを確認して、以下を実行。
$ ansible-playbook vagrant-httpd.yml

接続関係の問題が無ければ、無事に動作確認まで完了できる、、、はず。

解説っぽいもの

色々インストールしているけど

今回の最終目標であるhttpd動作確認のために、localhostへHTTPで接続を行なっています。
これを行なうための"uri"パッケージなのですが、Remote側に"httplib2"というPythonのパッケージを入れておかなければいけません。
これを入れるために"pip"が必要となり、"pip"を入れるために"easy_install"が必要となり、"easy_install"を入れるために"python-setuptools"が必要となるようです。

index.htmlをコピーしているけど

CentOSの"httpd"はデフォルトで"/var/www/html"以下にファイルが存在しておらず、そのまま"uri"でアクセスしてもエラーとなってしまうため、適当なHTMLファイルをコピーしておく必要があります。

"service"パッケージはあるけど

今回"service"パッケージを使用して、確かに"/etc/rc*.d"にファイルが作成されていました。
ですが、コマンドラインからchkconfigを実行してもサービスとして"httpd"が表示されませんでした。
"httpd"自体は動作しているので、後々コマンドからの調査や管理が必要となった場合に、混乱する基になるかもしれませんね。

17
16
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
17
16