zoukankan      html  css  js  c++  java
  • ansible安装nginx

    查看hosts文件

    [root@ansible playbooks]# ansible all --list
      hosts (4):
        192.168.1.114
        192.168.1.113
        192.168.1.111
        192.168.1.117
    

    第一次安装报错,发现被控的服务器没有nginx

    解决:

    [root@database ~]# cd /etc/yum.repos.d/
    [root@database yum.repos.d]# ll
    total 40
    -rw-r--r--. 1 root root 1664 Apr  7 18:01 CentOS-Base.repo
    -rw-r--r--. 1 root root 1309 Apr  7 18:01 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 Apr  7 18:01 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  314 Apr  7 18:01 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 Apr  7 18:01 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 Apr  7 18:01 CentOS-Sources.repo
    -rw-r--r--. 1 root root 7577 Apr  7 18:01 CentOS-Vault.repo
    -rw-r--r--. 1 root root  616 Apr  7 18:01 CentOS-x86_64-kernel.repo
    -rw-r--r--. 1 root root 2640 Mar 16 06:38 docker-ce.repo
    [root@database yum.repos.d]#  vim nginx.repo
    [root@database yum.repos.d]# cat nginx.repo
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    
    [nginx-mainline]
    name=nginx mainline repo
    baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=https://nginx.org/keys/nginx_signing.key
    [root@database yum.repos.d]#
    

    剧本:

    [root@ansible playbooks]# cat web-notls.yml
    ---
    - name: Configure dbservers with nginx
      hosts: dbservers
      become: True
      tasks:
        - name: install nginx
          yum: name=nginx update_cache=yes
        - name: copy nginx config file
          copy: src=files/nginx.conf dest=/etc/nginx/conf.d
        - 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
    [root@ansible playbooks]#
    
    [root@ansible templates]# cat index.html.j2
    <html>
      <head>
        <title>Welcome to ansible</title>
      </head>
      <body>
      <h1>nginx, configured by Ansible</h1>
      <p>If you can see this, Ansible successfully installed nginx.</p>
    
      <p>Running on {{ inventory_hostname }}</p>
      </body>
    </html>
    
    [root@ansible templates]#
    
    

    运行:

    [root@ansible playbooks]# ansible-playbook web-notls.yml
     _______________________________________
    < PLAY [Configure dbservers with nginx] >
     ---------------------------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
     ________________________
    < TASK [Gathering Facts] >
     ------------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    ok: [192.168.1.117]
     ______________________
    < TASK [install nginx] >
     ----------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    ok: [192.168.1.117]
     _______________________________
    < TASK [copy nginx config file] >
     -------------------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    ok: [192.168.1.117]
     ________________________
    < TASK [copy index.html] >
     ------------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    changed: [192.168.1.117]
     ______________________
    < TASK [restart nginx] >
     ----------------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    changed: [192.168.1.117]
     ____________
    < PLAY RECAP >
     ------------
               ^__^
               (oo)\_______
                (__)       )/
                    ||----w |
                    ||     ||
    
    192.168.1.117              : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
    
    

    结果:

  • 相关阅读:
    IServiceBehavior, IOperationBehavior,IParameterInspector
    System.IO.Pipelines——高性能IO(三)
    System.IO.Pipelines——高性能IO(二)
    System.IO.Pipelines——高性能IO(一)
    背包问题 —— 四种解法解题
    波音,自动驾驶bug未修复,致346人丧生!5个月内两次坠毁!其中,包括8名中国公民
    2018年Java生态行业报告
    为什么大公司一定要使用DevOps?
    设计微服务的最佳实践
    Spring Boot面试题
  • 原文地址:https://www.cnblogs.com/dalianpai/p/13277241.html
Copyright © 2011-2022 走看看