cloud-init tries to install NTP before even configuring the archives

Bug #1628337 reported by Andres Rodriguez
34
This bug affects 8 people
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Scott Moser
cloud-init (Ubuntu)
Fix Released
Critical
Unassigned
Xenial
Fix Released
Critical
Unassigned

Bug Description

== Begin SRU Template ==
[Impact]
When told to configure ntp, and the ntp package is not installed
in an image, cloud-init will attempt to install the package.

The problem here is that it currently tries to install the package before
it configures apt. As a result, no apt proxy or mirror configuration is
setup, and the stock image apt config is used.

[Test Case]
## Failure can be shown like this:
$ cat > user-data <<END
#cloud-config
ntp:
  servers: ['ntp.ubuntu.com']

apt:
  primary:
    - arches: [default]
      uri: http://us.archive.ubuntu.com/ubuntu/
END

$ release=xenial
$ name=x1
$ lxc init ubuntu-daily:$release $name "--config=user.user-data=$(cat user-data)"

# simulate a mirror that can't be reached by changing
# /etc/apt/sources.list to have a bogus mirror.
# what should happen is that cloud-init should apply apt config changes
# and render /etc/apt/sources.list from /etc/cloud/templates/
# and do the mirror substitution first.
#
# The bug is that cloud-init does not render apply the apt
# config before ntp runs and requests the package installation.

$ lxc file push - $name/etc/apt/sources.list <<EOF
deb http://bogus.example.com/ubuntu/ $release main restricted universe
EOF

$ lxc start $name

# wait for it to boot
$ while ! lxc exec $name -- [ -e /run/cloud-init/result.json ]; do sleep 1; done

$ lxc file pull $name/var/log/cloud-init-output.log - | egrep "^[EW]:"
W: Failed to fetch http://bogus.example.com/ubuntu/dists/xenial/InRelease Could not resolve 'bogus.example.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
E: Unable to locate package ntp
EOF

## The fix can be shown applied by subsequently
# push the broken sources.list back into image.

$ lxc file push - $name/etc/apt/sources.list <<EOF
deb http://bogus.example.com/ubuntu/ $release main restricted universe
EOF

## Now update container, clean and reboot to show first boot
$ lxc exec $name -- sh -c '
    p=/etc/apt/sources.list.d/proposed.list
    echo deb http://archive.ubuntu.com/ubuntu xenial-proposed main > "$p" &&
    apt-get update -q && apt-get -qy install cloud-init'
$ lxc exec $name -- sh -c '
    cd /var/lib/cloud && for d in *; do [ "$d" = "seed" ] || rm -Rf "$d"; done
    rm -Rf /var/log/cloud-init*'

$ lxc file pull $name/var/log/cloud-init-output.log - | egrep "^[EW]:" ||
      echo "FIX WORKED."

[Regression Potential]
The 'ntp' function is fairly new, and is only used if a user specifies
an ntp configuration as shown above. Regression chance is low then
and should be restricted to scenarios where users are providing
the ntp configuration.
== End SRU Template ==

cloud-init tries to install NTP package before it actually configures /etc/apt/sources.list.

In a closed MAAS environment where MAAS is limited to access to us.archive.ubuntu.com , cloud-init is trying to access to archive.ubuntu.com.

In commissioning, however, cloud-init is doing this:

1. cloud-init gets metadata from MAAS
2. cloud-init tries to install NTP from archive.ubuntu.com
3. cloud-init configures /etc/apt/sources.list with us.archive.ubuntu.com
4. cloud-init installs other packages.

Related branches

Scott Moser (smoser)
Changed in cloud-init:
status: New → Confirmed
importance: Undecided → Medium
Changed in cloud-init (Ubuntu):
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Andres Rodriguez (andreserl) wrote :

fwiw, this is really critical for us. Is causing all of our CI runs to fail.

Revision history for this message
Scott Moser (smoser) wrote :

fix seems fairly simple.
http://paste.ubuntu.com/23245011/

Revision history for this message
Ryan Harper (raharper) wrote :

Moving ntp to after apt module config seems like the right thing to do here.

Jon Grimm (jgrimm)
Changed in cloud-init (Ubuntu):
importance: Medium → Critical
Scott Moser (smoser)
Changed in cloud-init:
assignee: nobody → Scott Moser (smoser)
status: Confirmed → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.8-11-g02f6c4b-0ubuntu1

---------------
cloud-init (0.7.8-11-g02f6c4b-0ubuntu1) yakkety; urgency=medium

  * New upstream snapshot.
    - lxd: Update network config for LXD 2.3 [Stéphane Graber]
    - DigitalOcean: use meta-data for network configruation [Ben Howard]
    - ntp: move to run after apt configuration (LP: #1628337)

 -- Scott Moser <email address hidden> Thu, 29 Sep 2016 14:30:15 -0400

Changed in cloud-init (Ubuntu):
status: Confirmed → Fix Released
Changed in cloud-init (Ubuntu Xenial):
importance: Undecided → Critical
Scott Moser (smoser)
Changed in cloud-init (Ubuntu Xenial):
status: New → In Progress
Scott Moser (smoser)
description: updated
description: updated
Revision history for this message
Scott Moser (smoser) wrote :

I've uploaded this to xenial-proposed , the version with fix is 0.7.8-1-g3705bb5-0ubuntu1~16.04.3

https://launchpad.net/ubuntu/xenial/+queue?queue_state=1&queue_text=cloud-init

We need an SRU team member to replace 0.7.8-1-g3705bb5-0ubuntu1~16.04.2 in xenial-proposed with 0.7.8-1-g3705bb5-0ubuntu1~16.04.3

Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello Andres, or anyone else affected,

Accepted cloud-init into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/cloud-init/0.7.8-1-g3705bb5-0ubuntu1~16.04.3 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in cloud-init (Ubuntu Xenial):
status: In Progress → Fix Committed
tags: added: verification-needed
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

I tested 0.7.8-1-g3705bb5-0ubuntu1~16.04.3, it fixes the issue in our environment. Marking verification-done

tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.8-1-g3705bb5-0ubuntu1~16.04.3

---------------
cloud-init (0.7.8-1-g3705bb5-0ubuntu1~16.04.3) xenial-proposed; urgency=medium

  * ntp: move to run after apt configuration (LP: #1628337).

cloud-init (0.7.8-1-g3705bb5-0ubuntu1~16.04.2) xenial; urgency=medium

  * Support IPv6 config coming from initramfs. LP: #1621615.

 -- Scott Moser <email address hidden> Mon, 03 Oct 2016 12:22:26 -0400

Changed in cloud-init (Ubuntu Xenial):
status: Fix Committed → Fix Released
Revision history for this message
Martin Pitt (pitti) wrote : Update Released

The verification of the Stable Release Update for cloud-init has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Scott Moser (smoser) wrote :

This is fixed in cloud-init 0.7.9.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
amin (bjj1234567) wrote :

HI ,

My OS is :
root@ubuntu:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
root@ubuntu:~#

I see the same errors on MAAS events /logs .

Node post-installation failure - 'cloudinit' running modules for final Fri, 16 Feb. 2018 04:29:57
Node post-installation failure - 'cloudinit' running config-ntp with frequency once-per-instance Fri, 16 Feb. 2018 04:29:55

How can I check if the cloud-init fix ?

Thanks and Regards ,
Amine

Revision history for this message
David Britton (dpb) wrote :

@amin -- please file a new bug report if you are still seeing an error. You can reference this bug in that new one if you would like.

Make sure that new bug report is as detailed as you can be about the problem you are seeing.

Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.