Ansible Local script with Arguments yes/no having some issue

1,380 views
Skip to first unread message

Prabahar S

unread,
Nov 21, 2017, 1:16:53 AM11/21/17
to Ansible Project
Hi All,

Can someone give an idea about to run the script in local? My script having yes/no question. If I give "Yes" it'll run the script, "NO" it will terminate the script. So I need a playbook to execute this scenario. It's quite an urgency.


- hosts: test
  tasks:

        - name: Running Script
          run_once: true
          local_action: script /data/scripts/script.sh
          register: history
          

I have tried above playbook. it's not working and the throwing the error


 ansible-playbook testing.yml

PLAY [test] ************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************
ok: [unixpgtest1]

TASK [Running Script] *************************************************************************************************************************************************
fatal: [unixpgtest1 -> localhost]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 1, "stderr": "", "stdout": "\u001b[5m ############################################################\n\u001b[15m Hello Admin... Welcome to Script\n\u001b[5m ############################################################\n\u001b[0m\n\nNo server Arguments to the script are found.\n\nThe script will use the servers mentioned in the file \"\".\n\nBelow are the servers mentioned in the file /data/scripts/OS_PATCHING/Patching_Servers.txt\nunixpgtest1 test auto \n\n\nExiting....\n", "stdout_lines": ["\u001b[5m ############################################################", "\u001b[15m Hello Admin... Welcome to Script", "\u001b[5m ############################################################", "\u001b[0m", "", "No server Arguments to the script are found.", "", "The script will use the servers mentioned in the file \"\".", "", "Below are the servers mentioned in the file", "unixpgtest1 test auto ", "", "", "Exiting...."]}

NO MORE HOSTS LEFT *****************************************************************************************************************************************************************************************
        to retry, use: --limit @/etc/ansible/playbook/testing.retry

PLAY RECAP *************************************************************************************************************************************************************************************************
unixpgtest1                : ok=1    changed=0    unreachable=0    failed=1

Ryan Fisher

unread,
Nov 21, 2017, 7:42:16 PM11/21/17
to Ansible Project
Your script is being run, but it is exciting with a non-zero return code which causes the playbook to exit with a failure. This is the expected behavior, see this part of the output:

"msg": "non-zero return code", "rc": 1, 

If you don't want the playbook to fail when the script exits with a non-zero return, you need to set the failed_when: condition to your liking. Or, if you simply want to ignore all failures (from the perspective of Ansible), you can set ignore_errrors: True.

See these docs:

Reply all
Reply to author
Forward
0 new messages