0

I am trying to install and start nginx on my CentOS 6.7 test box.

My playbook

---
- 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

and what I got:

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   

It is bug or I am wrong in playbook? Thanks.

added

It seems, it fails on "Starting nginx service" task.

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  
  • It seems Install nginx package task is completely ignored. Did you run ansible-playbook on the correct playbook file? – yaegashi Aug 20 '15 at 20:07
1

I think nginx-release-centos-6-0.el6.ngx.noarch.rpm is an arch independent supporting package and it's insufficient for the full nginx installation. You also need to install the arch specific package found in i386 or x86_64 dirs.

I recommend you to set up the yum repository based on the official install instruction:

---
- 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
0

nginx-release-centos-6-0.el6.ngx.noarch.rpm is not nginx package, it is nginx repository package. When you install it, it will create nginx repository. So you need one more task to install actual nginx:

yum: name=nginx state=latest

You can check package description:

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

...

Summary : nginx repo configuration and pgp public keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.