Sorry to bring up an old thread - I’m trying to use the code below, and whilst it doesn’t error and the command appears to run, if I then move to the next Ansible command I’m getting an unreachable error which suggests that Ansible doesn’t realise it needs to re-create a new session. Output as below. I tried adding a pause after killing the SSH connection to see if that would make any difference (it doesn’t). If I break my playbook down into two components i…e
- Playbook 1 → Make change to remote shell, then run the SSH session kill code
- Playbook 2 → add interfaces using command based on shell change made in Playbook 1
This works fine as two executions of ansible-playbook. Only if I concatenate them into a single play do I get an issue.
Any thoughts?
thanks, Keith
`
TASK [kill cached ssh connection] *******************************************************************************************************************************************************
changed: [172.27.254.170 → localhost] => (item=172.27.254.170)
TASK [wait a few seconds] ***************************************************************************************************************************************************************
Pausing for 10 seconds
(ctrl+C then ‘C’ = continue early, ctrl+C then ‘A’ = abort)
ok: [172.27.254.170]
PLAY [172.27.254.170] *******************************************************************************************************************************************************************
TASK [Ccnfigure Interface eth1 to 1.2.3.4/24 and change state to on] ********************************************************************************************************************
failed: [172.27.254.170] (item=clish -c ‘set interface eth1 ipv4-address 1.2.3.4 mask-length 24’ -s) => {“item”: “clish -c ‘set interface eth1 ipv4-address 1.2.3.4 mask-length 24’ -s”, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: ( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" && echo ansible-tmp-1508773836.62-247443091731403="echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" ), exited with result 1, stdout output: CLINFR0329 Invalid command:‘/bin/sh -c ‘( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" && echo ansible-tmp-1508773836.62-247443091731403="echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" ) && sleep 0’’.\n”, “unreachable”: true}
failed: [172.27.254.170] (item=clish -c ‘set interface eth1 state on’ -s) => {“item”: “clish -c ‘set interface eth1 state on’ -s”, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: ( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" && echo ansible-tmp-1508773836.89-36032531829548="echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" ), exited with result 1, stdout output: CLINFR0329 Invalid command:‘/bin/sh -c ‘( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" && echo ansible-tmp-1508773836.89-36032531829548="echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" ) && sleep 0’’.\n”, “unreachable”: true}
fatal: [172.27.254.170]: UNREACHABLE! => {“changed”: false, “msg”: “All items completed”, “results”: [{“_ansible_item_result”: true, “item”: “clish -c ‘set interface eth1 ipv4-address 1.2.3.4 mask-length 24’ -s”, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: ( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" && echo ansible-tmp-1508773836.62-247443091731403="echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" ), exited with result 1, stdout output: CLINFR0329 Invalid command:‘/bin/sh -c ‘( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" && echo ansible-tmp-1508773836.62-247443091731403="echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.62-247443091731403
" ) && sleep 0’’.\n”, “unreachable”: true}, {“_ansible_item_result”: true, “item”: “clish -c ‘set interface eth1 state on’ -s”, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: ( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" && echo ansible-tmp-1508773836.89-36032531829548="echo CLINFR0329 Invalid command:'/bin/sh -c 'echo ~ && sleep 0''./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" ), exited with result 1, stdout output: CLINFR0329 Invalid command:‘/bin/sh -c ‘( umask 77 && mkdir -p "echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" && echo ansible-tmp-1508773836.89-36032531829548="echo CLINFR0329 Invalid command:'\"'\"'/bin/sh -c '\"'\"'echo ~ && sleep 0'\"'\"''\"'\"'./.ansible/tmp/ansible-tmp-1508773836.89-36032531829548
" ) && sleep 0’’.\n”, “unreachable”: true}]}
to retry, use: --limit @/home/krichards/Ansible-Local-Deployment_and_Setup/kr-test.retry
PLAY RECAP ******************************************************************************************************************************************************************************
172.27.254.170 : ok=4 changed=3 unreachable=1 failed=0
`