Currently trying to run just a simple playbook on an Ansible install on Centos7, everything is up to date. I can run a simple raw module and specify the host but when I run the playbook I have get a "cannot resolve host name"
Here are the logs
[root#ohnetwork01 playbooks]# ansible-playbook -vvvvvv -u user.user -k version_playbook.yaml
Using /etc/ansible/ansible.cfg as config file
SSH password:
Loaded callback default of type stdout, v2.0
PLAYBOOK: version_playbook.yaml ************************************************
1 plays in version_playbook.yaml
PLAY [Get version] *************************************************************
TASK [setup] *******************************************************************
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" && echo ansible-tmp-1466529280.8-264756931089857="` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" ) && sleep 0'
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" && echo ansible-tmp-1466529280.8-152708795243660="` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" ) && sleep 0'
<192.168.1.34> PUT /tmp/tmpymgKXv TO /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-264756931089857/" > /dev/null 2>&1 && sleep 0'
<192.168.1.33> PUT /tmp/tmpW5FEgv TO /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-152708795243660/" > /dev/null 2>&1 && sleep 0'
ok: [P-9396PXb.domain.local]
ok: [P-9396PXa.domain.local]
TASK [nxos_facts] **************************************************************
task path: /home/user/playbooks/version_playbook.yaml:8
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" && echo ansible-tmp-1466529281.26-258697976681834="` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" ) && sleep 0'
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" && echo ansible-tmp-1466529281.26-135897636845763="` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" ) && sleep 0'
<192.168.1.33> PUT /tmp/tmpvaaDMQ TO /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-258697976681834/" > /dev/null 2>&1 && sleep 0'
<192.168.1.34> PUT /tmp/tmpK7TYAS TO /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-135897636845763/" > /dev/null 2>&1 && sleep 0'
fatal: [P-9396PXa.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
fatal: [P-9396PXb.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit #version_playbook.retry
PLAY RECAP *********************************************************************
P-9396PXa.domain.local : ok=1 changed=0 unreachable=0 failed=1
P-9396PXb.domain.local : ok=1 changed=0 unreachable=0 failed=1
and here's the host file and playbook I'm using, insanely simple as I was just trying to test
#### Host entry ####
[ProdCoreSwitches]
P-9396PXa.domain.local ansible_host=192.168.1.33
P-9396PXb.domain.local ansible_host=192.168.1.34
#### Playbook ####
---
- name: Get version
connection: local
hosts: ProdCoreSwitches
tasks:
- nxos_facts:
host= "{{ inventory_hostname }}"
Anything I should be changing?
Edit: After changing the connection from local I get the following:
fatal: [P-9396PXa.domain.local]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ), exited with result 16: Syntax error while parsing '/bin/sh -c '( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ) && sleep 0''\n\n\nCmd exec error.\n", "unreachable": true}
Can you show the content of task "nxos_facts"? Also where did you define "{{ inventory_hostname }}" and what's the value(s)?
Related
When I run "ansible -m ping migservers -vvv" Im getting below error.
ansible -m ping migservers -vvv
ansible 2.8.1
config file = /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/ansible.cfg
configured module search path = [u'/home/extgw/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Jun 11 2019, 12:19:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/ansible.cfg as config file
host_list declined parsing /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/hosts as it did not pass it's verify_file() method
script declined parsing /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/hosts as it did not pass it's verify_file() method
auto declined parsing /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/hosts as it did not pass it's verify_file() method
Parsed /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/hosts inventory source with ini plugin
META: ran handlers
[WARNING]: While constructing a mapping from /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/group_vars/all/var.yml, line 4, column 1,
found a duplicate dict key (authorized_user). Using last defined value only.
[WARNING]: While constructing a mapping from /mnt/git/smart-egw-pre-production/automation-scripts/release-management-scripts/group_vars/all/var.yml, line 4, column 1,
found a duplicate dict key (dep_patches). Using last defined value only.
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: extgw
<10.0.40.207> ESTABLISH SSH CONNECTION FOR USER: extgw
<127.0.0.1> SSH: EXEC sshpass -d10 ssh -o BatchMode=yes -o ForwardAgent=yes -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o 'User="extgw"' -o ConnectTimeout=10 127.0.0.1 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1561617542.31-234782308603401 `" && echo ansible-tmp-1561617542.31-234782308603401="` echo /tmp/ansible-tmp-1561617542.31-234782308603401 `" ) && sleep 0'"'"''
<10.0.40.206> ESTABLISH SSH CONNECTION FOR USER: extgw
<10.0.40.207> SSH: EXEC sshpass -d10 ssh -o BatchMode=yes -o ForwardAgent=yes -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o 'User="extgw"' -o ConnectTimeout=10 10.0.40.207 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1561617542.31-227856382807600 `" && echo ansible-tmp-1561617542.31-227856382807600="` echo /tmp/ansible-tmp-1561617542.31-227856382807600 `" ) && sleep 0'"'"''
<10.0.40.206> SSH: EXEC sshpass -d10 ssh -o BatchMode=yes -o ForwardAgent=yes -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o 'User="extgw"' -o ConnectTimeout=10 10.0.40.206 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1561617542.32-254693221799990 `" && echo ansible-tmp-1561617542.32-254693221799990="` echo /tmp/ansible-tmp-1561617542.32-254693221799990 `" ) && sleep 0'"'"''
<10.0.40.207> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
<127.0.0.1> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
10.0.40.207 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
<10.0.40.206> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
10.0.40.206 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
127.0.0.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
I want to install package.json using ansible, I'm using the example from the docs, only thing different from this is that I'm using npm not nvm so the tasks look like this
- name: npm install (manual)
npm:
path:"{{ project_path }}"
executable: /usr/bin/npm
{{ project_path }} is path to package.json file, basically it's /srv/example.com/.
The result of this tasks is
TASK [angular : npm install (manual)] ******************************************
task path: /srv/example.com/orchestration/ansible/roles/angular/tasks/main.yml:16
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/language/npm.py
<default> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<default> EXEC /bin/sh -c 'echo ~ && sleep 0'
<default> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" && echo ansible-tmp-1540437954.12-74081721294328="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" ) && sleep 0'
<default> PUT /tmp/tmpkx6E4h TO /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py
<default> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/ /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py && sleep 0'
<default> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-anopitzukaokwawzhqmxqjfzoxjtozxh; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [default] => {
"changed": false,
"invocation": {
"module_args": {
"executable": "/usr/bin/npm",
"global": false,
"ignore_scripts": false,
"name": null,
"path": "/srv/example.com/",
"production": false,
"registry": null,
"state": "present",
"version": null
}
}
}
It does not do anything, why? How can I install my package.json, can someone please help me understand how to overcome this, thanks.
I am trying to vertically concatenate 2 files
The 1st file is roles/myrolename/files/requirements.dat
numpy
matplotlib
dask
and the 2nd file is ~/myprojects/myprojectname/requirements.txt
django
pywinrm
scipy
Here is my attempt to combine these 2 files, based on
this SO post
the include jinja2 documentation
Here is the task I am using
- name: Play to combine 2 files
hosts: localhost
connection: local
vars:
myprojects_path: myprojects
my_proj_name: myprojectname
tasks:
- name: Concatenate 2 files
template:
src: "roles/myrolename/templates/requirements.dat.j2"
dest: "{{ myprojects_path }}/{{ my_proj_name }}/requirements.dat"
Here is roles/myrolename/templates/requirements.dat.j2
{% include 'roles/myrolename/files/requirements.dat' %}
{% include myprojects_path + "/" + my_proj_name + "/" + "requirements.txt" %}
This task gives the error message (related to the 2nd include statement from roles/myrolename/templates/requirements.dat.j2)
fatal: [my_local_machine]: FAILED! => {"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt"}
This seems to suggest that Ansible is expecting that /home/wr/myprojects/myprojectname/requirements.txt is a template and not a file. However, the first include line does not throw an error. This is confusing me.
Is there a way I can use include to concatenate these 2 files with the jinja2 template, or is there another method to concatenate the 2 files?
EDIT 1:
I added {# a comment #} to the 1st line of requirements.txt. Here is the new ~/myprojects/myprojectname/requirements.txt
{# a comment #}
django
pywinrm
scipy
Then, I re-ran the playbook ansible-playbook test.yml -vvv. Here is the output
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: wr
<127.0.0.1> EXEC /bin/sh -c 'echo ~wr && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930 `" && echo ansible-tmp-1532962816.77-184726406959930="` echo /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930 `" ) && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930/ > /dev/null 2>&1 && sleep 0'
fatal: [wr-box]: FAILED! => {
"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt"
}
EDIT 2:
I tried to ask Ansible to treat the above requirements.txt (with {# a comment #} on 1st line) as a jinja2 template by re-naming the file. I renamed the file requirements.txt to requirements.txt.j2 and re-ran the playbook. It gives this output
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: wr
<127.0.0.1> EXEC /bin/sh -c 'echo ~wr && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507 `" && echo ansible-tmp-1532963056.03-76693523230507="` echo /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507 `" ) && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507/ > /dev/null 2>&1 && sleep 0'
fatal: [wr-box]: FAILED! => {
"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt.j2"
}
It still does not seem to find the template file, even though I have checked that it is indeed present at the location I specified.
Generally the include statement treats the file as a template. Also the file requirements.txt in your example is generally a template, without variables and with text only.
Does the file /home/wr/myprojects/myprojectname/requirements.txt exist?
Had any tried to use Ansible (ansible 1.9.4) Netscaler module ? I tried to use it but failed with error:
ansible localhost -m netscaler -a "nsc_host=nsc.example.com user=nscuser password=nscpassword name=node1.example.com type=service action=disable validate_certs=False"
localhost | FAILED >> {
"failed": true,
"msg": "'NoneType' object has no attribute 'read'"
}
with -vvvv output:
<localhost> REMOTE_MODULE netscaler nsc_host=nsc.example.com user= nscuser password=VALUE_HIDDEN name=node1.example.com type=service action=disable validate_certs=False
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1460868653.22-66856743808206 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1460868653.22-66856743808206 && echo $HOME/.ansible/tmp/ansible-tmp-1460868653.22-66856743808206']
<localhost> PUT /tmp/tmpAfQPY2 TO /home/supp/.ansible/tmp/ansible-tmp-1460868653.22-66856743808206/netscaler
<localhost> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/local/bin/python2.7 /home/supp/.ansible/tmp/ansible-tmp-1460868653.22- 66856743808206/netscaler; rm -rf /home/supp/.ansible/tmp/ansible-tmp- 1460868653.22-66856743808206/ >/dev/null 2>&1']
localhost | FAILED >> {
"failed": true,
"msg": "'NoneType' object has no attribute 'read'"
}
with unusable 1.9.5:
/usr/bin/ansible --version
ansible 1.9.5
configured module search path = None
/usr/bin/ansible localhost -m netscaler -a "nsc_host=nsc.example.com user= nscuser password=VALUE_HIDDEN name=node1.example.com type=service action=disable validate_certs=False" -vvvv
<localhost> REMOTE_MODULE netscaler nsc_host=nsc.example.com user= nscuser password=VALUE_HIDDEN name=node1.example.com type=service action=disable validate_certs=False
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620 && echo $HOME/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620']
<localhost> PUT /tmp/tmpiN_wRf TO /home/supp/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620/netscaler
<localhost> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python26 /home/supp/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620/netscaler; rm -rf /home/supp/.ansible/tmp/ansible-tmp-1460873442.75-215681661318620/ >/dev/null 2>&1']
localhost | FAILED >> {
"failed": true,
"msg": "'NoneType' object has no attribute 'read'"
}
note: localhost is not NETSCALER, it is a manage host.
I also tried to use the module in playbook but still failed.
Hope to hear suggestion from you .
Thanks.
While the error isn't very informative, the problem is a connectivity one.
The module has not been able to connect to the netscaler.
Check your network connection & ensure there are no firewalls in the way.
The root cause is from
response, info = fetch_url(self.module, request_url, data=data_json, headers=headers)
return json.load(response)
"response" got nothing back so is if "None" type and so json.load cannot read None.
A pull request with slightly more helpful error handling is at https://github.com/ansible/ansible-modules-extras/pull/2327
I am new to Ansible and would appreciate some help understanding why this playbook seems to execute OK but when I login to the remote host, the file isn't there and apache cannot be started.
Here is the playbook:
---
- name: Setup webservers
hosts: all
connection: local
tasks:
- name: copy test
sudo: yes
copy: src=/etc/ansible/app/test dest=/
- name: install Apache
sudo: yes
yum: name=httpd state=present
Here is the output:
root#ip-172-31-19-255 app]# ansible-playbook -vvv test.yml
PLAY [Setup webservers] *******************************************************
GATHERING FACTS ***************************************************************
<172.31.24.166> REMOTE_MODULE setup
<172.31.5.165> REMOTE_MODULE setup
<172.31.5.165> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547006.58-268185556939980 && echo $HOME/.ansible/tmp/ansible-tmp-1445547006.58-268185556939980']
<172.31.24.166> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547006.58-101316942599470 && echo $HOME/.ansible/tmp/ansible-tmp-1445547006.58-101316942599470']
<172.31.5.165> PUT /tmp/tmpCIgcvv TO /root/.ansible/tmp/ansible-tmp-1445547006.58-268185556939980/setup
<172.31.5.165> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445547006.58-268185556939980/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1445547006.58-268185556939980/ >/dev/null 2>&1']
<172.31.24.166> PUT /tmp/tmpAhOtGk TO /root/.ansible/tmp/ansible-tmp-1445547006.58-101316942599470/setup
<172.31.24.166> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445547006.58-101316942599470/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1445547006.58-101316942599470/ >/dev/null 2>&1']
ok: [172.31.5.165]
ok: [172.31.24.166]
TASK: [copy test] *************************************************************
<172.31.5.165> EXEC ['/bin/sh', '-c', u'rc=flag; [ -r /test ] || rc=2; [ -f /test ] || rc=1; [ -d /test ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != "xflag" ] && echo "${rc} "/test && exit 0; (python -c \'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nafile = open("\'/test\'", "rb")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())\' 2>/dev/null) || (python -c \'import sha; BLOCKSIZE = 65536; hasher = sha.sha();\nafile = open("\'/test\'", "rb")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())\' 2>/dev/null) || (echo \'0 \'/test)']
<172.31.24.166> EXEC ['/bin/sh', '-c', u'rc=flag; [ -r /test ] || rc=2; [ -f /test ] || rc=1; [ -d /test ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != "xflag" ] && echo "${rc} "/test && exit 0; (python -c \'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();\nafile = open("\'/test\'", "rb")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())\' 2>/dev/null) || (python -c \'import sha; BLOCKSIZE = 65536; hasher = sha.sha();\nafile = open("\'/test\'", "rb")\nbuf = afile.read(BLOCKSIZE)\nwhile len(buf) > 0:\n\thasher.update(buf)\n\tbuf = afile.read(BLOCKSIZE)\nafile.close()\nprint(hasher.hexdigest())\' 2>/dev/null) || (echo \'0 \'/test)']
<172.31.5.165> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547006.89-213853778271951 && echo $HOME/.ansible/tmp/ansible-tmp-1445547006.89-213853778271951']
<172.31.24.166> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547006.9-233414769988070 && echo $HOME/.ansible/tmp/ansible-tmp-1445547006.9-233414769988070']
<172.31.5.165> PUT /tmp/tmp6ejI0a TO /root/.ansible/tmp/ansible-tmp-1445547006.89-213853778271951/file
<172.31.5.165> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=twunfaumexxymoemhcbdsgwtgvhfstjt] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-twunfaumexxymoemhcbdsgwtgvhfstjt; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445547006.89-213853778271951/file; rm -rf /root/.ansible/tmp/ansible-tmp-1445547006.89-213853778271951/ >/dev/null 2>&1'"'"''
<172.31.24.166> PUT /tmp/tmpxpX_zM TO /root/.ansible/tmp/ansible-tmp-1445547006.9-233414769988070/file
<172.31.24.166> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=unwvfdmsujhcmoalkeqjhglkhuzbcqcs] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-unwvfdmsujhcmoalkeqjhglkhuzbcqcs; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445547006.9-233414769988070/file; rm -rf /root/.ansible/tmp/ansible-tmp-1445547006.9-233414769988070/ >/dev/null 2>&1'"'"''
ok: [172.31.5.165] => {"changed": false, "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "dest": "/test", "gid": 0, "group": "root", "mode": "0664", "owner": "root", "path": "/test", "size": 0, "state": "file", "uid": 0}
ok: [172.31.24.166] => {"changed": false, "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "dest": "/test", "gid": 0, "group": "root", "mode": "0664", "owner": "root", "path": "/test", "size": 0, "state": "file", "uid": 0}
TASK: [install Apache] ********************************************************
<172.31.5.165> REMOTE_MODULE yum name=httpd state=present
<172.31.5.165> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547007.04-58359634351509 && echo $HOME/.ansible/tmp/ansible-tmp-1445547007.04-58359634351509']
<172.31.24.166> REMOTE_MODULE yum name=httpd state=present
<172.31.24.166> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445547007.05-80567519499784 && echo $HOME/.ansible/tmp/ansible-tmp-1445547007.05-80567519499784']
<172.31.5.165> PUT /tmp/tmpN8TP3c TO /root/.ansible/tmp/ansible-tmp-1445547007.04-58359634351509/yum
<172.31.5.165> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=quaahxohwbrzkqkbezturfziaggexqqn] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-quaahxohwbrzkqkbezturfziaggexqqn; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1445547007.04-58359634351509/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1445547007.04-58359634351509/ >/dev/null 2>&1'"'"''
<172.31.24.166> PUT /tmp/tmpdtc7hX TO /root/.ansible/tmp/ansible-tmp-1445547007.05-80567519499784/yum
<172.31.24.166> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=cdasbsyfzpxxjubjsrchidaxvqblhmfx] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-cdasbsyfzpxxjubjsrchidaxvqblhmfx; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1445547007.05-80567519499784/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1445547007.05-80567519499784/ >/dev/null 2>&1'"'"''
ok: [172.31.24.166] => {"changed": false, "msg": "", "rc": 0, "results": ["httpd-2.2.31-1.6.amzn1.x86_64 providing httpd is already installed"]}
ok: [172.31.5.165] => {"changed": false, "msg": "", "rc": 0, "results": ["httpd-2.2.31-1.6.amzn1.x86_64 providing httpd is already installed"]}
PLAY RECAP ********************************************************************
172.31.24.166 : ok=3 changed=0 unreachable=0 failed=0
172.31.5.165 : ok=3 changed=0 unreachable=0 failed=0
Here is me looking for httpd:
root#ip-172-31-5-165 ~]# yum list installed httpd
Loaded plugins: priorities, update-motd, upgrade-helper
Error: No matching Packages to list
Any help would be great~ Cheers~
This is your problem:
connection: local
What you are doing is delegating these tasks to all run locally on the system that Ansible is running on, rather than running on the target hosts. That's why Apache isn't being installed on the target systems.
Also, the dest parameter in the copy task is a full path to a file, not just a path. So if you want to copy a file called foo.txt then you need to do something like this:
- name: copy foo.txt
copy: src=/path/to/source/foo.txt dest=/path/to/target/foo.txt
FYI, you will likely also want to do this once you get the yum task working:
- name: ensure apache is started
service: name=httpd enabled=true state=started
This task will ensure that apache is started and is also set to start up automatically if/when the server is rebooted.