首页 文章

无法使用ansible启动或停止niginx

提问于
浏览
-1

我无法使用ansible启动或停止niginx .

yml文件看起来像这样,

---
- hosts: loadbalancer
  become: true
  tasks:
   - name: install nginx
     apt: name=nginx state=present update_cache=yes

   - name: ensure nginx is installed
     service: 
        name: nginx 
        state: stopped

我正在使用ansible-playbook 2.5.1,有趣的是安装命令工作,第二个任务也返回执行了更改,但没有启动或停止nginx .

输出我得到,

播放[负载均衡器]任务[收集事实] **************************************** ****************************************确定:[172.17.0.3]任务[安装nginx] ************************************************ ********************************确定:[172.17.0.3]任务[确保安装nginx] **** ************************************************** ************************已更改:[172.17.0.3] PLAY RECAP 172.17.0.3:ok = 3已更改= 1无法访问= 0失败= 0

任何解释和解决方案都有帮

提前致谢 .

1 回答

  • 0

    changed: [172.17.0.3] 消息表示该服务处于已启动状态 . 事实上,在你的游戏中安装nginx时,会启动默认状态,所以如果你这样做:

    - name: install nginx
         apt: name=nginx state=present update_cache=yes
    

    你会得到:

    systemctl status nginx
    ● nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
       Active: active (running) since Sun 2018-05-13 09:00:00 UTC; 38s ago
    

    这意味着在运行时:

    - name: ensure nginx is installed
         service: 
            name: nginx 
            state: stopped
    

    您将停止服务(已更改为Ansible):

    TASK [ensure nginx is installed] *****************************************************************************************************
    changed: [ubuntu-1]
    

    检查服务,它被停止:

    systemctl status mginx
    Unit mginx.service could not be found.
    root@ubuntu-1:/home/vagrant# systemctl status nginx
    ● nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
       Active: inactive (dead) since Sun 2018-05-13 09:01:28 UTC; 12s ago
    

    除了所有这些解释之外,我建议安装Ansible 2.5.2,因为2.5.1有严重的列表错误 .

相关问题