cruddystuff
cruddystuff

Reputation: 27

Copying a file and installing apache via Ansible shows OK but not there when logged into remote server

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~

Upvotes: 0

Views: 174

Answers (1)

Bruce P
Bruce P

Reputation: 20759

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.

Upvotes: 1

Related Questions