导入template时,write the nginx config file之后的步骤不能有效执行
来源:3-7 Ansible playbooks常用模块案例操作

ZT403
2019-01-21
老师你好,请问
从write the nginx config file 之后的就开始错误,这个是哪里出现了问题呢。
我看了配置的文件,deploy.yml、main.yml、这些都没有问题,
不过在刚开始配置nginx的时候,
#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.e17.ngx.noarch.rpm
出现了nginx-release-centos-7-0.el7.ngx.noarch.rpm: 不是 rpm 软件包 (或者没有manifest)的报错,
在执行rpm --import /etc/pki/rpm-gpg/RPM* 后再执行成功。
3回答
-
一路向北
2019-01-29
这里在inventory下定义变量需要与template保证一致012019-01-30 -
ZT403
提问者
2019-01-22
deploy.yml
- name: Print server name and user to remote testbox
shell: "echo 'Currently {{ user }} is logining {{ server_name }}' > {{ output }}"
- name: create a file
file: 'path=/root/foo.txt state=touch mode=0755 owner=foo group=foo'
- name: copy a file
copy: 'remote_src=no src=roles/testbox/files/foo.sh dest=/root/foo.sh mode=0644 force=yes'
- name: check if foo.sh exists
stat: 'path=/root/foo.sh'
register: script_stat
- debug: msg="foo.sh exists"
when: script_stat.stat.exists
- name: run the script
command: 'sh /root/foo.sh'
- name: write the nginx config file
template: src=roles/testbox/templates/nginx.conf.j2 dest=/etc/nginx/nginx.conf
- name: ensure nginx is at the latest version
yum: pkg=nginx state=latest
- name: start nginx service
service: name=nginx state=started
nginx.conf.j2
# For more information on configuration, see:
user {{ user }};
worker_processes {{ worker_processes }};
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections {{ max_open_file }};
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
#include /etc/nginx/conf.d/*.conf;
server {
listen {{ port }} default_server;
server_name {{ server_name }};
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root {{ root }};
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
PLAY [testservers] **********************************************************************************************************************************************************************************************************************
[testservers]
test.example.com
[testservers:vars]
server_name=test.example.com
user=root
output=/root/test.txt
server_name=test.example.com
port=80
user=deploy
work_process=4
max_open_file=65506
root=/www
deploy.yml
- hosts: "testservers"
gather_facts: true
remote_user: root
roles:
- testbox
00 -
一路向北
2019-01-21
感谢这位同学的关注,请提供一下你的ansible脚本的内容
012019-01-29
相似问题