{"id":476,"date":"2022-12-21T15:28:47","date_gmt":"2022-12-21T15:28:47","guid":{"rendered":"https:\/\/www.aixperts.co.uk\/?p=476"},"modified":"2022-12-21T15:29:41","modified_gmt":"2022-12-21T15:29:41","slug":"using-ansible-command-return-code","status":"publish","type":"post","link":"https:\/\/www.aixperts.co.uk\/?p=476","title":{"rendered":"Using Ansible command return code"},"content":{"rendered":"\n<p>I was using the command module in Ansible but the command I was calling at the other end would cause the module to fail even on informational message. I believe this was partly due to the &#8216;rc&#8217; value in the output being non-zero.<\/p>\n\n\n\n<p>Googling and reading documentation showed a multitude or complex and not very accurate or not even working methods of responding to this return code.<\/p>\n\n\n\n<p>The module output was:<\/p>\n\n\n\n<p><code>{\"changed\": true, \"cmd\": [\"\/opt\/IBM\/ldap\/V6.4\/bin\/idslink\", \"-g\", \"-i\", \"-l\", \"32\", \"-f\"], \"delta\": \"0:00:01.881979\", \"end\": \"2022-12-21 15:08:38.942974\", \"failed_when_result\": false, \"msg\": \"non-zero return code\", <strong>\"rc\": 4,<\/strong><\/code> [&#8230;]<\/p>\n\n\n\n<p>The solution was quite simple:<\/p>\n\n\n\n<p><code>name: Relink 64 bit libraries<\/code><\/p>\n\n\n\n<p><code>when: ansible_os_family == \"AIX\"<br>command: \/opt\/IBM\/ldap\/V6.4\/bin\/idslink -g -i -l 64 -f<br>register: output<br>failed_when: output.rc not in [0, 2, 4 ]<\/code><\/p>\n\n\n\n<p>This ensures reeturn code 0, 2 and 4 are not treated as errors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was using the command module in Ansible but the command I was calling at the other end would cause the module to fail even on informational message. I believe this was partly due to the &#8216;rc&#8217; value in the &hellip; <a href=\"https:\/\/www.aixperts.co.uk\/?p=476\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[160,149],"tags":[157,159,158],"class_list":["post-476","post","type-post","status-publish","format-standard","hentry","category-ansible","category-automation","tag-ansible","tag-automation","tag-return-code"],"_links":{"self":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=476"}],"version-history":[{"count":1,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}