请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

导入template时,write the nginx config file之后的步骤不能有效执行

老师你好,请问
图片描述
从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

3回答

一路向北 2019-01-29 22:05:39

https://img1.sycdn.imooc.com//szimg/5c505d600001cba211260724.jpg
https://img1.sycdn.imooc.com//szimg/5c505d8400016bb910440594.jpg
这里在inventory下定义变量需要与template保证一致

0 回复 有任何疑惑可以回复我~
  • 提问者 ZT403 #1
    好的,谢谢老师
    回复 有任何疑惑可以回复我~ 2019-01-30 15:00:12
提问者 ZT403 2019-01-22 13:16:21

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


0 回复 有任何疑惑可以回复我~
一路向北 2019-01-21 23:22:08

感谢这位同学的关注,请提供一下你的ansible脚本的内容

0 回复 有任何疑惑可以回复我~
  • 提问者 ZT403 #1
    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
    回复 有任何疑惑可以回复我~ 2019-01-29 09:53:19
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信