2016-08-20 7 views
1

httpdをインストールするAWSにCentOSマシンがあります。私はbecome_method : sudoをrootとして動作させていますが、まだ解決できませんでした。私のリモートマシンに、Ansibleプレイブックを使ってhttpdをインストールすることができません

これは私の脚本です:

--- 
- hosts : aws 
    connection : ssh 
    remote_user : centos 
    become_method : sudo 
    gather_facts : yes 
    tasks : 
    - name : Connect to the remote host and executing yum updates 
    yum : name=* state=latest 
    - name : Installing HTTPD Server 
    yum : name=httpd state=latest 
    - name : Deploy the static website 
    copy : src=../files/index.html dest=/var/www/html/index.html owner=centos group=centos mode=0655 backup=yes 
    - name : Restart the HTTPD Service 
    service: name=httpd state=restarted 
    - name : Wait for the HTTPD port 80 to be listening 
    wait_for : host=ec2-54-152-85-197.compute-1.amazonaws.com 
    - name : Installing WGET to test the site 
    yum : name=wget state=latest 
    - name : Test the site 
    shell : /usr/bin/wget http://localhost 
    register : site_result 
    - name : Display the site output results 
    debug : var=site_result 

こうすることで、私は次のエラーが発生しました:

TASK [Connect to the remote host and executing yum updates] ******************** 
task path: /home/centos/Playbooks/example/example_playbook.yaml:8 
Using module file /usr/lib/python2.7/site-packages/ansible-2.2.0-py2.7.egg/ansible/modules/core/packaging/os/yum.py 
<ec2-54-152-85-197.compute-1.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: centos 
<ec2-54-152-85-197.compute-1.amazonaws.com> SSH: EXEC ssh -q -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/centos/AnsibleKeyPair.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=centos -o ConnectTimeout=10 -o ControlPath=/home/centos/.ansible/cp/ansible-ssh-%h-%p-%r ec2-54-152-85-197.compute-1.amazonaws.com '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"'' 
fatal: [ec2-54-152-85-197.compute-1.amazonaws.com]: FAILED! => { 
"changed": true, 
"failed": true, 
"invocation": { 
    "module_args": { 
     "conf_file": null, 
     "disable_gpg_check": false, 
     "disablerepo": null, 
     "enablerepo": null, 
     "exclude": null, 
     "install_repoquery": true, 
     "list": null, 
     "name": [ 
      "*" 
     ], 
     "state": "latest", 
     "update_cache": false, 
     "validate_certs": true 
    }, 
    "module_name": "yum" 
}, 
"msg": "You need to be root to perform this command.\n", 
"rc": 1, 
"results": [ 
    "Loaded plugins: fastestmirror\n" 
] 
} 
+0

ちょっとフィードバックがあって、あなたの構文がちょっと変わって読みにくくなってしまいました。一般的に、YAMLでは、コロンの後にスペースを使用します。 – smiller171

答えて

1

あなたはAnsibleはあなたがbecome: yesを追加する必要がありますrootに昇格させるのに十分接近していますあなたのプレイブックに。ただ、ノートとして

- hosts: aws 
    connection: ssh 
    remote_user: centos 
    become_method: sudo 
    become: yes 
    gather_facts: yes 
    tasks: 
    [...] 

、明示的に指定する必要はありません。connectionbecome_methodgather_facts、彼らはすべてのそれらの値がデフォルトになります。

EDIT:デフォルトでは

CentOSのはDefault: requirettyで出てくるので、あなたがそれを固定する2つの方法があります。

  1. コメントアウトrequiretty
  2. 無効にpipeliningファイルsudoersには、追加の行をpipelinig: noあなたのプレイブックに
関連する問題