Unable to install httpd on my remote machine using Ansible playbook
<p>I have a CentOS machine in AWS on which I intended to install <strong>httpd</strong> which requires us to be root. I am using <code>become_method : sudo</code> to work as root but still I could not solve it.</p>

<p>This is my playbook:</p>

<pre><code>---
- 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
</code></pre>

<p>By doing this, I encountered the following error:</p>

<pre><code>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
&lt;ec2-54-152-85-197.compute-1.amazonaws.com&gt; ESTABLISH SSH CONNECTION FOR USER: centos
&lt;ec2-54-152-85-197.compute-1.amazonaws.com&gt; 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 &amp;&amp; sleep 0'"'"''
fatal: [ec2-54-152-85-197.compute-1.amazonaws.com]: FAILED! =&gt; {
"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"
]
}
</code></pre>