Unable playbook does not copy files, gives no errors

My ansible playbook only copies one of the files I specified. The playbus terminates without errors. If I run the same command outside of the 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 start playbook with

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

      

and it exits without any error saying all tasks are ok

The only file that's actually copied is the last file, which is the logstash-forwarder in init.d. Adding chkconfig also works

If I run the command with ansible -m (instead of playbook) on one of the files that have not been copied 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 are not copied to the destination host in my workbook, but will work by invoking the irreplaceable copy module?

+3


source to share


1 answer


Ansible job cannot have multiple actions.

Copy the files into four tasks and they 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 also used Action Shorthand and replaced the notation action: module ...

with module: ...

. It does not change the way the code works, but it is the preferred way to call a module.

+1


source







All Articles