yoshiislandblog.net
元営業の駆け出しアラサーSEが、休日にMACと戯れた際の殴り書きメモ。日々勉強。日々進歩。

この記事は3年以上前に書かれた記事で内容が古い可能性があります

O’Reilly「初めてのAnsible」でハマったこと

2016-07-17

O’Reilly「初めてのAnsible」でハマったこと

P.28

★エラー

hogehoge$ ansible-playbook playbooks/web-notls.yml
 ______________________ 
< TASK [restart nginx] >
 ---------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
fatal: [testserver]: FAILED! => {"changed": false, "failed": true, "msg": "nginx: [emerg] unexpected \"}\" in /etc/nginx/sites-enabled/default:12\nnginx: configuration file /etc/nginx/nginx.conf test failed\n"}
____________________

★playbookの中身修正(コロンの追加)

vagrant@precise64:~$ sudo find / -name nginx.conf
/vagrant/playbooks/files/nginx.conf
/etc/nginx/nginx.conf

vagrant@precise64:~$ cat /vagrant/playbooks/files/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/sharenginx/html;
index index.html index.htm;

server_name localhost;

location / {
try_files $uri $uri/ =404
}
}

vagrant@precise64:~$ vim /vagrant/playbooks/files/nginx.conf
vagrant@precise64:~$ cat /vagrant/playbooks/files/nginx.conf 
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    
    root /usr/share/nginx/www;
    index index.html index.htm;
    
    server_name localhost;
    
    location / {
        try_files $uri $uri/ =404;
    }
}

vagrant@precise64:~$

★ymlファイルの中身修正(ファイルパス)

hogehoge$ cat playbooks/web-notls.yml
# Configure webserver with nginx
- name: Configure webserver with nginx
hosts: webservers
become: True
tasks:
- name: install nginx
apt: name=nginx update_cache=yes

- name: copy nginx config file
copy:
src=nginx.conf
dest=/etc/nginx/sites-available/default

- name: enable configuration
file:
dest=/etc/nginx/sites-enabled/default
src=/etc/nginx/sites-available/default
state=link

- name: copy index.html
template:
src=templates/index.html.j2
dest=/usr/share/nginx/html/index.html
mode=0644

- name: restart nginx
service: name=nginx state=restarted

hogehoge$ sudo vim playbooks/web-notls.yml
hogehoge$ cat playbooks/web-notls.yml
# Configure webserver with nginx
- name: Configure webserver with nginx
hosts: webservers
become: True
tasks:
- name: install nginx
apt: name=nginx update_cache=yes

- name: copy nginx config file
copy:
src=nginx.conf
dest=/etc/nginx/sites-available/default

- name: enable configuration
file:
dest=/etc/nginx/sites-enabled/default
src=/etc/nginx/sites-available/default
state=link

- name: copy index.html
template:
src=templates/index.html.j2
dest=/usr/share/nginx/www/index.html
mode=0644

- name: restart nginx
service: name=nginx state=restarted