Question

clout-init apt-key "invalid armor header"

I am using cloud-init to provision my droplet with custom apt repositories, and I have the public keys inline using this form:

apt:
  primary:
    - arches: [default]
      search_dns: true
  security:
    - arches: [default]
      search_dns: true
  sources:
    nodejs:
      source: "deb http://deb.nodesource.com/node_8.x stretch main"
      key: |
        -----BEGIN PGP PUBLIC KEY BLOCK-----
        Version: GnuPG v1
        mQINBFObJLYBEADkFW8HMjsoYRJQ4nCYC/6Eh0yLWHWfCh+/9ZSIj4w/pOe2V6V+
        <snip>
        -----END PGP PUBLIC KEY BLOCK-----

And I get this error in /var/log/cloud-init-output.log

2018-05-26 11:05:19,807 - cc_apt_configure.py[ERROR]: failed to add apt GPG Key to apt keyring
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py", line 530, in add_apt_key_raw
    util.subp(['apt-key', 'add', '-'], data=key.encode(), target=target)
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1850, in subp
    cmd=args)
cloudinit.util.ProcessExecutionError: Unexpected error while running command.
Command: ['apt-key', 'add', '-']
Exit code: 2
Reason: -
Stdout: -
Stderr: Warning: apt-key output should not be parsed (stdout is not a terminal)
        gpg: invalid armor header: mQINBFObJLYBEADkFW8HMjsoYRJQ4nCYC/6Eh0yLWHWfCh+/9ZSIj4w/pOe2V6V+\n
2018-05-26 11:05:19,811 - util.py[WARNING]: Running module apt-configure (<module 'cloudinit.config.cc_apt_configure' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py'>) failed

This seems to be a bug in cloud-init, but I can’t even figure out a workaround. I’ve tried putting the key in the YAML as a flow scalar instead of a block scalar, but that gave the same error (at a different point in the key input).


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

I ran into this exact same issue, and this is literally the only google result for this specific cloud-init error. The problem is the lack of a space after the “-----BEGIN PGP PUBLIC KEY BLOCK-----” line. It should look like this instead:

      key: |
        -----BEGIN PGP PUBLIC KEY BLOCK-----

        Version: GnuPG v1
        mQINBFObJLYBEADkFW8HMjsoYRJQ4nCYC/6Eh0yLWHWfCh+/9ZSIj4w/pOe2V6V+
        <snip>
        -----END PGP PUBLIC KEY BLOCK-----

The docs actually show it without the extra newline, but it’s definitely necessary for it to function correctly.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel