Search code examples
ansiblecloudansible-inventoryredhat-containers

Ansible file creation fails without any error


After running the the below Ansible Yaml file the output shows file is created and the content is changed

The YAML File

---
- hosts: all
  gather_facts: yes
  connection: local
  tasks:
    - name: Check the date on the server.
      action: command touch /opt/b
    - name: cat the Content
      action: command cat /opt/b

Running the Playbook

root@my-ubuntu:/var/lib/awx/projects/test# ansible-playbook  main.yml  

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

TASK [setup] *******************************************************************
ok: [ansible-ubuntu-1604-db]

TASK [Check the date on the server.] *******************************************
changed: [ansible-ubuntu-1604-db]
 [WARNING]: Consider using file module with state=touch rather than running touch


TASK [cat the Content] *********************************************************
changed: [ansible-ubuntu-1604-db]

PLAY RECAP *********************************************************************
ansible-ubuntu-1604-db     : ok=3    changed=2    unreachable=0    failed=0   

The Message Display changed=2 and tasks doesnt created any file

ubuntu@ansible-ubuntu-1604-db:~$ ls -l /opt/
total 0

The Env

  1. Ansible Controller on the MAC Local Desktop
  2. Taget Node is on Cloud

Solution

  • With connection: local in your playbook, you tell Ansible to execute all tasks on your local ansible controller. So file is created on your local machine.

    Remove connection: local and try again.