CentOS 6.7 上的 Ansible nginx 服务

CentOS 6.7 上的 Ansible nginx 服务

我正在尝试在我的 CentOS 6.7 测试盒上安装并启动 nginx。

我的剧本

---
- hosts: testing
  tasks:

  - name: Install nginx package
    yum: name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present
    sudo: yes

  - name: Starting nginx service
    service: name=nginx state=started
    sudo: yes

我得到了什么:

ansible-playbook playbooks/setup_nginx.yml  -vvvv

PLAY [testing] **************************************************************** 

GATHERING FACTS *************************************************************** 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> REMOTE_MODULE setup
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440082617.5-357433622496 && echo $HOME/.ansible/tmp/ansible-tmp-1440082617.5-357433622496'
<192.168.1.7> PUT /tmp/tmpDVadb0 TO /root/.ansible/tmp/ansible-tmp-1440082617.5-357433622496/setup
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440082617.5-357433622496/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1440082617.5-357433622496/ >/dev/null 2>&1'
ok: [192.168.1.7]

TASK: [Starting nginx service] ************************************************ 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> REMOTE_MODULE service name=nginx state=started
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440082618.06-217670671742177 && echo $HOME/.ansible/tmp/ansible-tmp-1440082618.06-217670671742177'
<192.168.1.7> PUT /tmp/tmpS9pPju TO /root/.ansible/tmp/ansible-tmp-1440082618.06-217670671742177/service
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=mhcceyzpppkgjqdohbazdghdyxzgozkq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-mhcceyzpppkgjqdohbazdghdyxzgozkq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440082618.06-217670671742177/service; rm -rf /root/.ansible/tmp/ansible-tmp-1440082618.06-217670671742177/ >/dev/null 2>&1'"'"''
failed: [192.168.1.7] => {"failed": true}
msg: no service or tool found for: nginx

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/setup_nginx.retry

192.168.1.7              : ok=1    changed=0    unreachable=0    failed=1   

这是错误还是我在剧本中错了?谢谢。

添加

看来,它在“启动 nginx 服务”任务上失败了。

ansible-playbook playbooks/setup_nginx.yml  -vvvv

PLAY [testing] **************************************************************** 

GATHERING FACTS *************************************************************** 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> REMOTE_MODULE setup
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440146573.93-179846503048866 && echo $HOME/.ansible/tmp/ansible-tmp-1440146573.93-179846503048866'
<192.168.1.7> PUT /tmp/tmprLXtDd TO /root/.ansible/tmp/ansible-tmp-1440146573.93-179846503048866/setup
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440146573.93-179846503048866/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1440146573.93-179846503048866/ >/dev/null 2>&1'
ok: [192.168.1.7]

TASK: [Setting up nginx repository] ******************************************* 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'rc=flag; [ -r /etc/yum.repos.d/nginx.repo ] || rc=2; [ -f /etc/yum.repos.d/nginx.repo ] || rc=1; [ -d /etc/yum.repos.d/nginx.repo ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != "xflag" ] && echo "${rc} "/etc/yum.repos.d/nginx.repo && exit 0; (python -c '"'"'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1(); afile = open("'"'"'/etc/yum.repos.d/nginx.repo'"'"'", "rb") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'"'"' 2>/dev/null) || (python -c '"'"'import sha; BLOCKSIZE = 65536; hasher = sha.sha(); afile = open("'"'"'/etc/yum.repos.d/nginx.repo'"'"'", "rb") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'"'"' 2>/dev/null) || (echo '"'"'0 '"'"'/etc/yum.repos.d/nginx.repo)'
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440146577.61-182195475857563 && echo $HOME/.ansible/tmp/ansible-tmp-1440146577.61-182195475857563'
<192.168.1.7> PUT /tmp/tmpWef98J TO /root/.ansible/tmp/ansible-tmp-1440146577.61-182195475857563/file
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=nexyrajvvcwztliiwybfvivgrzfjsksq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-nexyrajvvcwztliiwybfvivgrzfjsksq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440146577.61-182195475857563/file; rm -rf /root/.ansible/tmp/ansible-tmp-1440146577.61-182195475857563/ >/dev/null 2>&1'"'"''
ok: [192.168.1.7] => {"changed": false, "checksum": "39e5562257da539bf330df83d33879d3aa32ad67", "dest": "/etc/yum.repos.d/nginx.repo", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "path": "/etc/yum.repos.d/nginx.repo", "secontext": "unconfined_u:object_r:etc_t:s0", "size": 109, "state": "file", "uid": 0}

TASK: [Install nginx package] ************************************************* 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> REMOTE_MODULE yum name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440146578.31-123436309041285 && echo $HOME/.ansible/tmp/ansible-tmp-1440146578.31-123436309041285'
<192.168.1.7> PUT /tmp/tmpcr7txw TO /root/.ansible/tmp/ansible-tmp-1440146578.31-123436309041285/yum
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=kocdoeeplindfbghqgvyngpfyybjxwap] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-kocdoeeplindfbghqgvyngpfyybjxwap; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1440146578.31-123436309041285/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1440146578.31-123436309041285/ >/dev/null 2>&1'"'"''
ok: [192.168.1.7] => {"changed": false, "msg": "", "rc": 0, "results": ["http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm: Nothing to do"]}

TASK: [Starting nginx service] ************************************************ 
<192.168.1.7> ESTABLISH CONNECTION FOR USER: root
<192.168.1.7> REMOTE_MODULE service name=nginx state=started
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440146582.22-244037760484684 && echo $HOME/.ansible/tmp/ansible-tmp-1440146582.22-244037760484684'
<192.168.1.7> PUT /tmp/tmpl7NIQY TO /root/.ansible/tmp/ansible-tmp-1440146582.22-244037760484684/service
<192.168.1.7> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 192.168.1.7 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=hhzkesasgpvhlwbmgckouzbsnovgzpmr] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-hhzkesasgpvhlwbmgckouzbsnovgzpmr; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440146582.22-244037760484684/service; rm -rf /root/.ansible/tmp/ansible-tmp-1440146582.22-244037760484684/ >/dev/null 2>&1'"'"''
failed: [192.168.1.7] => {"failed": true}
msg: no service or tool found for: nginx

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/setup_nginx.retry

192.168.1.7              : ok=3    changed=0    unreachable=0    failed=1  

答案1

我认为nginx-release-centos-6-0.el6.ngx.noarch.rpm这是一个独立于 arch 的支持包,对于完整的 nginx 安装来说它是不够的。您还需要安装在中找到的特定于 arch 的包i386或者x86_64目录。

我建议您根据以下内容设置 yum 存储库官方安装说明:

---
- hosts: testing
  tasks:

  - name: Setting up nginx repository
    copy:
      dest: /etc/yum.repos.d/nginx.repo
      content: |
        [nginx]
        name=nginx repo
        baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
        gpgcheck=0
        enabled=1
    sudo: yes

  - name: Install nginx package
    yum: name=nginx state=present
    sudo: yes

  - name: Starting nginx service
    service: name=nginx state=started
    sudo: yes

答案2

nginx-release-centos-6-0.el6.ngx.noarch.rpm 不是 nginx 包,它是 nginx 存储库包。当你安装它时,它将创建 nginx 存储库。因此,您还需要完成一项任务来安装实际的 nginx:

yum: name=nginx state=latest

您可以查看包说明:

rpm -qip nginx-release-centos-6-0.el6.ngx.noarch.rpm

...

摘要:nginx repo 配置和 pgp 公钥

相关内容