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これがアーチ独立サポートパッケージであり、完全なnginxインストールには十分ではないと思います。また、次の場所にあるアーチ関連パッケージをインストールする必要があります。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をインストールするには、少なくとも1つの作業を完了する必要があります。

yum: name=nginx state=latest

パッケージの説明を見ることができます。

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

...

要約:nginx repo設定とpgp公開鍵

関連情報