What does sleep 0 do in a shell script and what does it do if it used in the ansible SSH config to append after each command?

笑着哭i 提交于 2021-02-10 12:47:53

问题


What does sleep 0 do in a shell script? I read the man page for sleep and it says "delay for a specified amount of time" And the argument NUMBER specifies this time in SECONDS (by default).

But I see ansible using sh -c 'echo ~ec2-user && sleep 0' to start with each task. Also, it uses this at the end of each remote command it is firing.

I didn't find any special case mention of sleep 0 on the man page and based on the functionality of the sleep command it doesn't make any sense to have sleep 0.

The sleep command on my server is from GNU coreutils 8.22

After looking into this for some more time, here are few things that I have learned,

  1. this is a SSH configuration given to the ansible,
  2. each time ansible using SSH to execute a task it is running SSH with -C with multiple options. These are not part of playbook or task.
  3. I looked for ansible configuration on ansible page here. Checked all files and Env variables but found nothing related to ssh
  4. Checked the /etc/ssh/ssh_config there are not all the parameters/arguments that I see in the SSH that ansible is doing
  5. In the inventory as well the host is mentioned just like this ansible_host=localhost ansible_user=ec2-user

e.g. log lines at the beginning when ansible executes any task:

 <localhost> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="ec2-user"' -o C
onnectTimeout=120 -o ControlPath=/home/ec2-user/.ansible/cp/6bc5a26ee4 localhost '/bin/sh -c '"'"'echo ~ec2-user && sleep 0'"'"''
<localhost> (0, '/home/ec2-user\n', '')
<localhost> ESTABLISH SSH CONNECTION FOR USER: ec2-user

I'm executing an ansible playbook written by one team, there is no one in that team I can talk to. I'm struggling to find where Ansible is taking all these arguments it is using in each SSH and why is it using this sleep 0

来源:https://stackoverflow.com/questions/65052086/what-does-sleep-0-do-in-a-shell-script-and-what-does-it-do-if-it-used-in-the-ans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!