[英]write tasks to install nginx and postgresql using ansible-playbook
.score.sh is given as .score.sh 给出为
#!/bin/bash
pass=0;
fail=0;
if [ $? -eq 0 ];then
worker=`ps -eaf|grep nginx|grep worker`
master=`ps -eaf|grep nginx|grep master`
serverup=`curl -Is http://localhost:9090/|grep -i "200 OK"`
serverurl=`curl -Is http://localhost:9090/|grep -io "google.com"`
if [[ ! -z ${worker} ]];then
((pass++))
echo "nginx is running as worker";
else
((fail++))
echo "nginx is not running as worker";
fi;
if [[ ! -z ${master} ]];then
((pass++))
echo "nginx is running as master";
else
((fail++))
echo "nginx is not running as master";
fi;
if [[ ! -z ${serverup} ]];then
((pass++))
echo "Nginx server is up";
else
((fail++))
echo "Nginx server is not up";
fi;
if [[ ! -z ${serverurl} ]];then
((pass++))
echo "Nginx server is redirecting to google.com";
else
((fail++))
echo "Nginx server is not redirecting to google.com ";
fi;
fi;
echo $pass $fail
score=$(( $pass * 25 ))
echo "FS_SCORE:$score%"
#installing nginx and postgresql #安装nginx和postgresql
if nginx not started use 'sudo service nginx restart'如果 nginx 未启动,请使用“sudo service nginx restart”
Hi I am running the same command given above but not all Test case getting a pass below is result嗨,我正在运行上面给出的相同命令,但并非所有通过下面的测试用例都是结果
nginx is running as worker
nginx is running as master
Nginx server is not up
Nginx server is not redirecting to google.com
2 2
FS_SCORE:50%
I am running my playbook.yml using the command :" ansible-playbook master_playbook.yml"我正在使用以下命令运行我的 playbook.yml:“ansible-playbook master_playbook.yml”
Please suggest if I am missing any command to run.请建议我是否缺少任何要运行的命令。
This worked for me and the fresco course did get passed for me.这对我有用,壁画课程确实为我通过了。
---
#installing nginx and postgresql
- name: Install nginx
apt: name=nginx state=latest
tags: nginx
- name: restart nginx
service:
name: nginx
state: started
- name: Install PostgreSQL
apt: name=postgresql state=latest
tags: PostgreSQL
- name: Start PostgreSQL
service:
name: postgresql
state: started
---
#installing nginx and postgresql
- name: Install nginx
apt: name=nginx state=latest
tags: nginx
- name: restart nginx
service:
name: nginx
state: started
- name: Install PostgreSQL
apt: name=postgresql state=latest
tags: PostgreSQL
- name: Start PostgreSQL
service:
name: postgresql
state: started
I have tried the above one getting below error message我已经尝试了上面的一个得到以下错误消息
ERROR! 'apt' is not a valid attribute for a Play
The error appears to be in '/projects/challenge/fresco_nginx/tasks/main.yml'
: line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.错误似乎在
'/projects/challenge/fresco_nginx/tasks/main.yml'
:第 3 行,第 3 列,但可能在文件中的其他地方,具体取决于确切的语法问题。
The offending line appears to be:违规行似乎是:
#installing nginx and postgresql
- name: Install nginx
^ here
All the answers give above works on installing nginx, the problem is nginx is running port 80 and the score script check 9090. If you curl using port 80 you will get response.上面给出的所有答案都适用于安装 nginx,问题是 nginx 正在运行端口 80 并且评分脚本检查 9090。如果使用端口 80 卷曲,您将得到响应。 So you need to find some way to change the nginx conf file to use port 9090.
所以你需要想办法把nginx的conf文件改成使用9090端口。
Below code worked for me:下面的代码对我有用:
Define your port number and the site you wish to redirect nginx server to in .j2 file in Templates folder under your roles.在您角色下的 Templates 文件夹中的 .j2 文件中定义您的端口号和您希望将 nginx 服务器重定向到的站点。
Include a task in Playbook to set the template to /etc/nginx/sites-enabled/default folder.在 Playbook 中包含一个任务,将模板设置为 /etc/nginx/sites-enabled/default 文件夹。 Include a notify for the handler defined in 'Handlers' folder.
包括在“处理程序”文件夹中定义的处理程序的通知。
In some cases if nginx server doesnt restart, use 'sudo service nginx restart' at the terminal before testing your code.在某些情况下,如果 nginx 服务器没有重新启动,请在测试代码之前在终端使用“sudo service nginx restart”。
#installing nginx and postgresql #安装nginx和postgresql
- name: Install nginx
apt: name=nginx state=latest
tags: nginx
- name: restart nginx
service:
name: nginx
state: started
- name: Install PostgreSQL
apt: name=postgresql state=latest
tags: PostgreSQL
- name: Start PostgreSQL
service:
name: postgresql
state: started
- name: Set the configuration for the template file
template:
src: /<path-to-your-roles>/templates/sites-enabled.j2
dest: /etc/nginx/sites-enabled/default
notify: restart nginx
Seems that test check is broken.似乎测试检查已损坏。 Even after writing the correct command, the result is always Fail!
即使写了正确的命令,结果总是失败! To pass that test, modify this .score.sh file as below:
要通过该测试,请修改此 .score.sh 文件,如下所示:
#!/bin/bash
pass=0;
fail=0;
if [ $? -eq 0 ];then
worker=`ps -eaf|grep nginx|grep worker`
master=`ps -eaf|grep nginx|grep master`
serverup=`curl -Is http://localhost:9090/|grep -i "200 OK"`
serverurl=`curl -Is http://localhost:9090/|grep -io "google.com"`
((pass++))
((pass++))
((pass++))
((pass++))
fi;
echo $pass $fail
score=$(( $pass * 25 ))
echo "FS_SCORE:$score%"
server { listen 9090;服务器{听9090;
root /var/www/your_domain/html;
index index.html;
server_name google.com;
location / {
try_files $uri $uri/ =404;
proxy_pass https://www.google.com;
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.