是否有可能在云初始化脚本 运行 之前延迟詹金斯连接到奴隶

Is it possible to delay jenkins from connecting to a slave before the cloud init script has run

我有一个云初始化脚本

#cloud-config
package_upgrade: true

packages:
 - openjdk-8-jdk
 - apt-transport-https
 - git
 - jq

groups:
  - docker

users:
 - default
 - name: jenkins
   groups: docker
   homedir: /var/lib/jenkins
   lock_passwd: true
   ssh_authorized_keys:
     - ssh-rsa xyz

启动 ubuntu 18.04 AMI 时提供给 jenkins ec2-plugin。

当 jenkins 尝试连接到日志显示的实例时:

INFO: Verifying: java -fullversion sh: 1: java: not found

Nov 01, 2018 8:22:10 PM null INFO: Installing: sudo yum install -y java-1.8.0-openjdk.x86_64 sudo: no tty present and no askpass program specified

Nov 01, 2018 8:22:10 PM null WARNING: Failed to install: sudo yum install -y java-1.8.0-openjdk.x86_64

sh: 1: java: not found ERROR: Unable to launch the agent for Ubuntu 18.04 (i-xxx) java.io.EOFException: unexpected stream termination

如果我在一段时间后(2/3 分钟)再次尝试手动连接到代理,一切正常:

Agent successfully connected and online

cloud-init脚本是否应该在SSH连接之前有运行?

我在使用 Amazon Linux AMI 时从未遇到过这种问题,我以相同的方式(通过云初始化脚本)安装了 java 8。这是亚马逊 linux 运行 的云初始化脚本与 ubuntu 的具体方式吗?

最后我决定安装 java 并创建一个新的 AMI 来完全避免这个问题。

我认为也许我对云初始化 运行 完全连接之前的期望可能不正确,主要是因为 the documentation

中的评论

Allow enough time for the instance to launch and execute the directives in your user data, and then check to see that your directives have completed the tasks you intended.

也许帮助解决此问题的一种方法可能是在安装时停止 运行 命令中的 sshd,然后在所有完成后重新启动它,希望 Jenkins 仅在一切完成后才连接准备好了。