2016-08-20 3 views
1

Ich habe eine CentOS-Maschine in AWS, auf der ich installieren wollte httpd, die uns als root erfordert. Ich benutze become_method : sudo, um als root zu arbeiten, aber ich konnte es nicht lösen.Ich kann httpd nicht auf meinem Remote-Computer mit Ansible playbook installieren

Das ist mein Textbuch ist:

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

Dadurch dies traf ich folgende Fehlermeldung:

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

Nur ein bisschen Feedback, Ihre Syntax ist ein bisschen seltsam und macht es schwerer zu lesen. Im Allgemeinen verwenden Sie in YAML nur ein Leerzeichen nach einem Doppelpunkt, nicht davor und danach. – smiller171

Antwort

1

Sie sind nah genug, lassen ansible Sie become: yes hinzufügen müssen Wurzel erheben zu deinem Spielbuch.

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

Nur als Anmerkung, Sie müssen nicht explizit angeben: connectionbecome_methodgather_facts, werden sie alle Standard auf diese Werte.

EDIT:

standardmäßig kommt CentOS mit Default: requiretty aus, so haben Sie zwei Möglichkeiten der Befestigung es:

  1. Kommentieren Sie die Zeile mit requiretty in sudoers Datei
  2. Disable pipelining Hinzufügen pipelinig: no in Ihrem playbook