Zulkifal Sahibzada
Zulkifal Sahibzada

Reputation: 11

ansible playbook runs but does not run any tasks

I am new to ansible, created a playbook which runs but does not perform any tasks. Here is my task in a role called copy, this task copies multiple files from ansible server to remote servers.


- name: Copy Files
  copy:
  src: "{{ item.src }}"
  dest: "{{ item.dest }}"
  with_items:
    - { src: 'audit.rules' , dest: '/etc/audit' }
    - { src: 'issue' , dest: '/etc' }
    - { src: 'issue.net' , dest: '/etc' }
    - { src: 'sshd_config' , dest: '/etc/ssh/' }
    - { src: 'hosts' , dest: '/etc' }
    - { src: 'rsyslog.conf' , dest: '/etc/' }
    - { src: 'sysctl.conf' , dest: '/etc/' }
    - { src: 'ntp.conf' , dest: '/etc/' }

Here is my main playbook

- hosts: all
  user: root
  roles:
    - copy

Here is output when I run it, but it does not copy anything to destination hosts

[root@hq-lxdev1-ansiblem ansible]# ansible-playbook -i hosts playbook.yml
SSH password:

PLAY [all] **********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [10.x.x.x]
        to retry, use: --limit @/etc/ansible/playbook.retry

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
10.x.x.x              : ok=1    changed=0    unreachable=0    failed=0

Not sure what is going on. Any help to troubleshoot this issue will highly be appreciated.

Upvotes: 1

Views: 3742

Answers (2)

ilias-sp
ilias-sp

Reputation: 6685

i think src and dest arguments need to be intended 1 level more that copy. please try this file and check it works:

---
- hosts: rhel-blue
  gather_facts: false

  tasks:
  - name: Copy Files
    copy:
      src: "{{ item.src }}"
      dest: "{{ item.dest }}"
    with_items:
      - { src: '/etc/hosts' , dest: '/tmp' }
      - { src: '/etc/issue' , dest: '/tmp' }

output:

[root@ansible ILIAS]# ansible-playbook copy_files.yml 

PLAY [rhel-blue] ****************************************************************************************************************************************************************************************************

TASK [Copy Files] ***************************************************************************************************************************************************************************************************
changed: [rhel-blue] => (item={u'dest': u'/tmp', u'src': u'/etc/hosts'})
changed: [rhel-blue] => (item={u'dest': u'/tmp', u'src': u'/etc/issue'})

PLAY RECAP **********************************************************************************************************************************************************************************************************
rhel-blue                  : ok=1    changed=1    unreachable=0    failed=0   

[root@ansible ILIAS]# 

Upvotes: 0

Adam Miller
Adam Miller

Reputation: 927

I think you need to indent src and dest over one, but if that is the fix then there's probably something Ansible should be warning about or possibly erroring.

Upvotes: 0

Related Questions