I’m running a playbook that should create 2 folders in a loop. If the folder is not existing, I wish to get a message that folders was created
In my scenario, folder 1 already exists and only folder 2 was created. But the message was skipped – I’m guessing that the register is being updated on every loop and the last task is getting the last update of the register. My goal Is to show a message on every folder that was created. Thanks *Playbook:* - hosts: gw become: true become_user: hdfs vars: folders: - /folder1 - /folder2 tasks: - name: create Main HDFS folders shell: hadoop fs -mkdir {{ item }} register: result ignore_errors: yes with_items: "{{ folders }}" - debug: msg: " {{ result }}" - debug: msg: folder created when: result is not failed *Output:* *PLAY [gw] ******************************************************************************************************************************************************************************** *TASK [Gathering Facts] ******************************************************************************************************************************************************************* *ok: [10.201.51.16]* *TASK [create Main HDFS folders] ********************************************************************************************************************************************************** *failed: [10.201.51.16] (item=/folder1) => {"ansible_loop_var": "item", "changed": true, "cmd": "hadoop fs -mkdir /folder1", "delta": "0:00:02.575512", "end": "2020-05-05 06:41:14.912389 ", "item": "/folder1", "msg": "non-zero return code", "rc": 1, "start": "2020-05-05 06:41:12.336877", "stderr": "mkdir: `/folder1': File exists", "stderr_lines": ["mkdir: `/folder1': Fi le exists"], "stdout": "", "stdout_lines": []}* *changed: [10.201.51.16] => (item=/folder2)* *...ignoring* *TASK [debug] ***************************************************************************************************************************************************************************** *ok: [10.201.51.16] => {* * "msg": " {'msg': u'All items completed', 'failed': True, 'changed': True, 'results': [{'stderr_lines': [u\"mkdir: `/folder1': File exists\"], 'ansible_loop_var': u'item', u'end': u' 2020-05-05 06:41:14.912389', u'failed': True, u'stdout': u'', u'changed': True, u'rc': 1, u'start': u'2020-05-05 06:41:12.336877', u'cmd': u'hadoop fs -mkdir /folder1', 'item': u'/folde r1', u'delta': u'0:00:02.575512', u'invocation': {u'module_args': {u'creates': None, u'executable': None, u'_uses_shell': True, u'strip_empty_ends': True, u'_raw_params': u'hadoop fs -m kdir /folder1', u'removes': None, u'argv': None, u'warn': True, u'chdir': None, u'stdin_add_newline': True, u'stdin': None}}, 'stdout_lines': [], u'stderr': u\"mkdir: `/folder1': File e xists\", u'msg': u'non-zero return code'}, {'stderr_lines': [], 'ansible_loop_var': u'item', u'end': u'2020-05-05 06:41:18.125812', 'failed': False, u'stdout': u'', u'changed': True, u' rc': 0, 'item': u'/folder2', u'cmd': u'hadoop fs -mkdir /folder2', u'stderr': u'', u'delta': u'0:00:02.609342', u'invocation': {u'module_args': {u'creates': None, u'executable': None, u '_uses_shell': True, u'strip_empty_ends': True, u'_raw_params': u'hadoop fs -mkdir /folder2', u'removes': None, u'argv': None, u'warn': True, u'chdir': None, u'stdin_add_newline': True, u'stdin': None}}, 'stdout_lines': [], u'start': u'2020-05-05 06:41:15.516470'}]}"* *}* *TASK [debug] ***************************************************************************************************************************************************************************** *skipping: [10.201.51.16]* *PLAY RECAP ******************************************************************************************************************************************************************************* *10.201.51.16 : ok=3 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=1* -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c99ebdf2-bba2-44d2-9e18-e582ae8edc27%40googlegroups.com.