さて、いよいよWordpressのインストール。
まずは、Wordpress用のnginxコンフィグファイルの準備。
$ sudo /etc/ansible/conoha-test/templete/wp-default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
まあ、先に作った”default.conf”と大差ありません。
“location /”の”index”が異なることぐらいでしょうか。
で、Playbookがこちら。
$ sudo vi /etc/ansible/conoha-test/04_wp-install.yml
- hosts: conoha-test
vars:
become: yes
remote_user: conoha
tasks:
- name: wordpressデータベース作成
mysql_db:
name: wordpress
state: present
- name: wordpressユーザ作成し、wordpress.* にすべての権限を与える
mysql_user:
name: wordpress
password: "VFR$5tgb%$Jh2"
priv: "wordpress.*:ALL"
host: localhost
state: present
- name: wordpressダウンロード
get_url:
url=https://ja.wordpress.org/wordpress-4.5.3-ja.tar.gz
dest=/root/
- name: wordpress解凍
shell: tar zxvf /root/wordpress-4.5.3-ja.tar.gz chdir=/usr/share/nginx
- name: wordpress所有権変更
shell: chown -R nginx:nginx /usr/share/nginx/wordpress
- name: html移動
shell: mv /usr/share/nginx/html /usr/share/nginx/html.org
- name: wordpress移動
shell: mv /usr/share/nginx/wordpress /usr/share/nginx/html
- name: 50x.htmlコピー
shell: cp /usr/share/nginx/html.org/50x.html /usr/share/nginx/html
- name: wp用default.conf転送
copy:
src=/etc/ansible/conoha-test/templete/wp-default.conf
dest=/etc/nginx/conf.d/default.conf
backup=yes
- name: nginx再起動
service: name=nginx state=restarted
で、これを実行。
$ sudo ansible-playbook /etc/ansible/conoha-test/04_wp-install.yml -K SUDO password: PLAY [conoha-test] ************************************************************* TASK [setup] ******************************************************************* Enter passphrase for key '/etc/ansible/conoha-test/.ssh/conoha-test_ansible_ras':
と、conohaのパスワードを入力して、sshキーのパスワードを入力すれば、実行されるでしょう。
無事に完了したならば、Webブラウザより、
“http://conoha-test/”にアクセスすればWordpressの設定画面が表示されるかと。
とまあ、こんな感じでAnsibleでWordpressのインストールができたかと。。。。
コメント