1

I have a cloud init script

#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

Which is given to the jenkins ec2-plugin when starting an ubuntu 18.04 AMI.

When jenkins tries to connect to the instance the logs show:

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

If I try to connect to the agent manually again after some time has elapsed (2/3 mins) all is fine:

Agent successfully connected and online

Should the cloud-init script have run before the SSH connection?

I have never had this trouble when using Amazon Linux AMI's where I install java 8 in the same way (via a cloud init script). Is this something specific to the way amazon linux runs cloud init scripts vs ubuntu?

David
  • 7,652
  • 21
  • 60
  • 98

1 Answers1

0

In the end I decided it was easier to install java and create a new AMI to fully avoid this issue.

I think that perhaps my expectations that cloud init would run fully before connecting might be incorrect, mainly because of this comment in 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.

Perhaps one approach to help solve this might be to stop sshd in the run commands while things install and then start it again when all done, hopefully Jenkins would then connect only once everything is ready.

Community
  • 1
  • 1
David
  • 7,652
  • 21
  • 60
  • 98