0

I've got a host server which runs Jenkins. I'd like Jenkins to automatically create new containers and prepare those containers with SALT. The ultimate purpose is to use these containers to test code.

What is the best way to create a new container, install salt-minion, and then provision the server with salt?

I've tried something along the lines of lxc-attach -n myContainer -- salt-call --local state.highstate but I'm running into problems doing that. If i run lxc-attach -n [name] -- [command] manually on the command line it works. However, doing this from a script gives me errors.

lxc-start -n "$1" -d
lxc-attach -n "$1" -- apt-get update

...results in...

Starting the container 'test2'...
Err http://archive.ubuntu.com trusty InRelease
Err http://archive.ubuntu.com trusty-updates InRelease
Err http://archive.ubuntu.com trusty Release.gpg
  Could not resolve 'archive.ubuntu.com'
Err http://security.ubuntu.com trusty-security InRelease
Err http://security.ubuntu.com trusty-security Release.gpg
  Could not resolve 'security.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Could not resolve 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease  

... and multiple more errors. I'm running both the script and the commands manually on the command line as the same user.

What could I be doing wrong here?

sbrattla
  • 1,456
  • 3
  • 26
  • 48

1 Answers1

0

It appears that i attempted to run apt-get update too quickly after i started the container (in the background). The network as apparently not ready, and this all commands (which relied on network) failed.

I added sleep 5s to the provisioning script, and it worked fined.

lxc-start -n "$1" -d
sleet 5
lxc-attach -n "$1" -- apt-get update
sbrattla
  • 1,456
  • 3
  • 26
  • 48