coreos / bugs

Issue tracker for CoreOS Container Linux
https://coreos.com/os/eol/
146 stars 30 forks source link

line 1: cannot unmarshal !!str `preseed...` into types.Config #2159

Closed IRobL closed 6 years ago

IRobL commented 6 years ago

Issue Report

Bug Occurrence

Reading the documentation and experimenting with converting what seems to be a cloud-config file into an ignition script is only bringing me a great sadness.

I would be grateful for the creation of a better understanding of how to convert a cloud-config file to an ignition script even for people who are new to computers.

Steps to Recreate

  1. A person gets a computer.
  2. The person decides containerization is a smart approach to computering and builds a vmware-iso repo that can deploy coreos against an ESXi hypervisor machine.
  3. The person vacations in SF and realizes that he or she needs to work away from their ESXi-production environment and begins re-working things to use virtual box
  4. The person sees that CoreOS behaves quite oddly when virtualbox is the deployment target
  5. The person becomes filled with self doubt over the course of 20+ hrs of researching, documentation reading and trial and error

Example code

(install.yml)

#cloud-config
ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
hostname: coreos-vm
coreos:
  units:
    - name: gitlab.service
      command: start
      runtime: yes
      enable: yes
      content: |
        [Unit]
        Description=gitlab server
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/mkdir -p /srv/gitlab/data/git-data/repositories
        ExecStartPre=-/usr/bin/chmod 2770 /srv/gitlab/data/git-data/repositories
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=-/usr/bin/docker pull gitlab/gitlab-ce:latest
        ExecStart=/usr/bin/docker run \
          --name %p \
          --hostname gitlab.example.com \
          --publish 443:443 \
          --publish 80:80 \
          --publish 23:22 \
          --volume /srv/gitlab/config:/etc/gitlab \
          --volume /srv/gitlab/logs:/var/log/gitlab \
          --volume /srv/gitlab/data:/var/opt/gitlab \
          gitlab/gitlab-ce:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target

    - name: mail-in-a-box.service
      command: start
      runtime: yes
      enable: yes
      content: |
        [Unit]
        Description=mail-in-a-box container
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=-/usr/bin/docker pull mtrnord/mailinabox:latest
        ExecStart=/usr/bin/docker run \
          --name %p \
          --publish 8025:25 \
          --env DOMAIN=example.com \
          mtrnord/mailinabox:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target

    - name: smail.service
      command: start
      runtime: yes
      enable: yes
      content: |
        [Unit]
        Description=mail catcher
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=/usr/bin/docker pull schickling/mailcatcher:latest
        ExecStart=/usr/bin/docker run \
          -p 1080:1080 \
          --name %p \
          --publish 8025:25 \
          schickling/mailcatcher:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target
  oem:
    id: vagrant
    name: Vagrant
    version-id: 0.1
    home-url: http://www.vagrantup.com/
    bug-report-url: https://github.com/coreos/coreos-overlay

(Vagrantfile)

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'

# Make sure the vagrant-ignition plugin is installed
required_plugins = %w(vagrant-ignition)

plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
  puts "Installing plugins: #{plugins_to_install.join(' ')}"
  if system "vagrant plugin install #{plugins_to_install.join(' ')}"
    exec "vagrant #{ARGV.join(' ')}"
  else
    abort "Installation of one or more plugins has failed. Aborting."
  end
end

Vagrant.configure("2") do |config|
  config.ssh.insert_key = false
  config.ssh.private_key_path = "~/.ssh/id_rsa"

  config.vm.define "coreos-vm" do |virtualbox|
    virtualbox.vm.hostname = "coreos-vm"
    virtualbox.vm.box = "coreos-stable"
    virtualbox.vm.box_url = "https://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json"
    virtualbox.ssh.private_key_path = "preseed/coreos/vagrant"

    ip = "172.16.3.53"
    virtualbox.vm.network :private_network, ip: ip, auto_config: false
    virtualbox.ignition.ip = ip
    config.ssh.insert_key = false

    config.ssh.username = "core"

    config.vm.provider :virtualbox do |v|
      v.gui = false
      v.memory = 4096
      v.cpus = 1
      v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      v.customize ["modifyvm", :id, "--ioapic", "on"]

      v.functional_vboxsf = false
      v.check_guest_additions = false

      config.ignition.config_obj = v

      config.ignition.enabled = true
      config.ignition.ip = ip

      # How do I make the below happen if all I have is a cloud-config file :(

      # config.vm.provision :file,
      #   :source => "preseed/coreos/install.yml",
      #   :destination => "/tmp/vagrantfile-user-data"
      # config.vm.provision :shell,
      #   :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/",
      #   :privileged => true

    end
  end

end

(attempted conversion)

$  ct <<< preseed/coreos/install.yml
error: yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `preseed...` into types.Config
Failed to parse config
ajeddeloh commented 6 years ago

ct converts a Container Linux Config (which is different than a cloud-config, but still yaml) into an Ignition config. The Provisioning with Container Linux Configs and Migrating from Cloud Configs documentation should help.

In this case, using

ct <<< preseed/coreos/install.yml

is redirecting the string preseed/coreos/install.yml to ct's standard in. To redirect the contents of the file use

ct < preseed/coreos/some_container_linux_config.yml
IRobL commented 6 years ago

Thanks for the help @ajeddeloh, I hugely appreciate it! I didn't realize what tipple less than symbols actually did. Additionally somehow the 'migrating docs' didn't turn up for me natrually. What it links to, the container linux config options page is particularly useful in my migration efforts.

I think my googling for stuff like 'ignition options' and 'convert cloud-config into ignition' was what was slowing me down because I really needed to be searching for converting to container linux configuration syntax.

I was getting other errors when using ct to transpile my cloud-config script that looked like this:

warning at line 2, column 1
Config has unrecognized key: ssh_authorized_keys
warning at line 4, column 1
Config has unrecognized key: hostname
warning at line 5, column 1
Config has unrecognized key: coreos

Here's my final container linux configuration script if this Issue googles well and is of interest to others:

passwd:
  users:
    - name: core
      ssh_authorized_keys:
        - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key

systemd:
  units:
    - name: gitlab.service
      enable: true
      contents: |
        [Unit]
        Description=gitlab server
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/mkdir -p /srv/gitlab/data/git-data/repositories
        ExecStartPre=-/usr/bin/chmod 2770 /srv/gitlab/data/git-data/repositories
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=-/usr/bin/docker pull gitlab/gitlab-ce:latest
        ExecStart=/usr/bin/docker run \
          --name %p \
          --hostname gitlab.example.com \
          --publish 443:443 \
          --publish 80:80 \
          --publish 23:22 \
          --volume /srv/gitlab/config:/etc/gitlab \
          --volume /srv/gitlab/logs:/var/log/gitlab \
          --volume /srv/gitlab/data:/var/opt/gitlab \
          gitlab/gitlab-ce:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target

    - name: mail-in-a-box.service
      enable: true
      contents: |
        [Unit]
        Description=mail-in-a-box container
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=-/usr/bin/docker pull mtrnord/mailinabox:latest
        ExecStart=/usr/bin/docker run \
          --name %p \
          --publish 8025:25 \
          --env DOMAIN=example.com \
          mtrnord/mailinabox:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target

    - name: smail.service
      enable: true
      contents: |
        [Unit]
        Description=mail catcher
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutSec=0
        Restart=always
        ExecStartPre=-/usr/bin/docker kill %p
        ExecStartPre=-/usr/bin/docker rm %p
        ExecStartPre=/usr/bin/docker pull schickling/mailcatcher:latest
        ExecStart=/usr/bin/docker run \
          -p 1080:1080 \
          --name %p \
          --publish 8025:25 \
          schickling/mailcatcher:latest
        ExecStop=/usr/bin/docker stop %p

        [Install]
        WantedBy=multi-user.target