LoginSignup
0
0

More than 3 years have passed since last update.

Apacheインストール(Ansible)

Last updated at Posted at 2019-10-24

はじめに

Ansibleを使用してApacheインストールを行う際の手順を記述します
サンプルアプリケーションはgithubになります

前提事項

Ansibleセットアップ手順はREADMEを参照ください
アプリケーション環境構築イメージはアプリケーション環境構築(Ansible)を参照ください

Apacheインストール(Ansible)

Apacheインストールを行うplaybookを定義します

ファイル 内容
変数ファイル ドメイン名等の変数を定義します
タスクファイル Apache関連のパッケージのインストールや設定変更等を定義します

Apache関連のパッケージインストール

Apache関連のパッケージをインストールします

- name: Apache関連のパッケージインストール
  apt:
    force_apt_get: yes
    state: latest
    name:
      - apache2

各項目の説明は以下のとおり

項目 内容
force_apt_get 警告を回避するためにapt-get使用を指定します
※詳細は#56832を参照ください
state latestを指定して最新バージョンをインストールします
name apache2を指定します

Apache設定変更

Apacheの設定を変更します

- name: 管理者ドメイン変更
  lineinfile:
    dest: /etc/apache2/sites-available/000-default.conf
    regexp: "ServerAdmin"
    line: '        ServerAdmin {{ user_domain }}'
    state: present

- name: デフォルトのDocumentRoot無効化
  lineinfile:
    dest: /etc/apache2/sites-available/000-default.conf
    regexp: "DocumentRoot"
    line: "        #DocumentRoot /var/www/html"
    state: present

各項目の説明は以下のとおり

項目 内容
dest 設定ファイルのパスを指定します
regexp 変更対象の文字列を指定します
line 置換する文字列を指定します
state presentを指定して設定変更済の場合はスキップします

Apacheサービス再起動

Apacheサービスを再起動します

- name: Apacheサービス再起動
  service:
    name: apache2
    enabled: yes
    state: restarted

各項目の説明は以下のとおり

項目 内容
name apache2を指定します
enabled yesを指定してサーバ起動時にサービスの起動を行います
state restartedを指定して再起動を行います

参考情報

0
0
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
0
0