AnsibleでとりあえずのLAMP環境してみる
VagrantとAnsibleでCentOSの環境を用意してみる
の続き
AnsibleでとりあえずのLAMP環境してみる。
下記をインストールするプレイブックを作成する。
・Apache(DocumentRootは/vagrantに変更)
・PHP
・MySQL5.6
・phpMyAdmin
$ vi playbook.yml
--- - hosts: 127.0.0.1 connection: local sudo: yes vars: mysql_user_name: vagrant mysql_user_password: vagrant tasks: # # Apache # - name: Apacheをインストール yum: name=httpd - name: Apacheを起動 service: name=httpd state=started enabled=yes - name: DocumentRootを/vagrantに変更 replace: dest=/etc/httpd/conf/httpd.conf regexp='DocumentRoot "/var/www/html"' replace='DocumentRoot "/vagrant"' notify: - restart httpd - name: .htaccessを有効にする replace: dest=/etc/httpd/conf/httpd.conf regexp='AllowOverride None' replace='AllowOverride All' notify: - restart httpd # # PHP # - name: PHPをインストール yum: name={{item}} with_items: - php - php-mbstring - php-mysql - name: PHPをタイムゾーンの設定 replace: > dest=/etc/php.ini regexp="^;date\.timezone =" replace="date.timezone = Asia/Tokyo" # # MySQL5.6 # - name: MySQL5.6のリポジトリを追加 command: > yum -y install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm creates=/etc/yum.repos.d/mysql-community.repo - name: MySQLをインストール yum: name={{item}} with_items: - mysql-server - MySQL-python - name: MySQLを起動 service: name=mysqld state=started enabled=yes - name: MySQLのユーザーを追加 mysql_user: name={{ mysql_user_name }} password={{ mysql_user_password }} priv=*.*:ALL # # phpMyAdmin # - name: phpMyAdminのインストール yum: name=phpMyAdmin enablerepo=epel - name: アクセス権限の変更 replace: > dest=/etc/httpd/conf.d/phpMyAdmin.conf regexp=" Deny from All" replace=" #Deny from All" notify: - restart httpd handlers: - name: restart httpd service: name=httpd state=restarted
プレイブックを実行する。
$ ansible-playbook playbook.yml