Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible playbook doesn't copy files, does not give error

My ansible playbook is only copying one of the files that I have specified. The playbook runs to completion without any errors. If I run the same command outside of a playbook it will copy

My very simple playbook

---
- hosts: "dudes"
  vars:
    remote_user: root
tasks:
    - name: Installs logstash-forwarder rpm
      yum: name=logstash-forwarder state=present disable_gpg_check=yes

    - name: Add the certs init and etc files into place
      action: copy src=/etc/ansible/files/logstash-forwarder/logstash-forwarder.crt dest=/etc/pki/tls/certs/ owner=root group=root mode=644
      action: copy src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-etc dest=/etc/logstash-forwarder owner=root group=root mode=644 force=yes
      action: copy src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-etc-sysconfig dest=/etc/sysconfig/logstash-forwarder owner=root group=root mode=644 force=yes
      action: copy src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-init-d dest=/etc/init.d/logstash-forwarder mode=0755

    - name: add logstash forwarder to chkconfig
      command: chkconfig --add logstash-forwarder
      notify:
            - start logstash-forwarder
handlers:
    - name: start logstash-forwarder
      service: name=logstash-forwarder enabled=yes state=started

I run the playbook with

ansible-playbook -l doozy logstash-forwarder-dudes.yml 

and it completes without any errors, saying all tasks are OK

The only file that actually gets copied is the last file, which is the logstash-forwarder into init.d. The chkconfig add also seems to work

If I run the command with ansible -m (instead of the playbook) on one of the files that didn't copy before, it will copy them without error

ansible -m copy -a "src=/etc/ansible/files/logstash-forwarder/logstash-forwarder.crt dest=/etc/pki/tls/certs/ owner=root group=root mode=644" doozy

I'm not sure why the files do not end up getting copied to the desination host in my playbook, but will work by calling the ansible copy module?

like image 207
Party Time Avatar asked Aug 07 '14 03:08

Party Time


1 Answers

There can't be multiple actions in Ansible task.

Copy the files in four tasks and it should work:

- name: Copy logstash-forwarder.crt
  copy: src=/etc/ansible/files/logstash-forwarder/logstash-forwarder.crt dest=/etc/pki/tls/certs/ owner=root group=root mode=644

- name: Copy /etc/logstash-forwarder
  copy: src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-etc dest=/etc/logstash-forwarder owner=root group=root mode=644 force=yes

- name: Copy /etc/sysconfig/logstash-forwarder
  copy: src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-etc-sysconfig dest=/etc/sysconfig/logstash-forwarder owner=root group=root mode=644 force=yes

- name: Copy /etc/init.d/logstash-forwarder
  copy: src=/etc/ansible/files/logstash-forwarder/logstash-forwarder-init-d dest=/etc/init.d/logstash-forwarder mode=0755

In the code I've also used Action Shorthand and replaced action: module ... notation with module: .... It doesn't change the way the code works but is the preferred way to call a module.

like image 80
Pasi H Avatar answered Sep 29 '22 13:09

Pasi H