1

How can I do this?

#cloud-config

users:
  - name: dev
    ssh-authorized-keys:
      - ssh-rsa AB3NzaC1yc...
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

packages:
  - mysql-client
  - libmysqlclient-dev
  - mysql-server

package-update: true
package_upgrade: true

runcmd:

#
# SSH
#
  - sed -i -e '/^Port/s/^.*$/Port 22/' /etc/ssh/sshd_config
  - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
  - sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config
  - sed -i -e '$aAllowUsers dev' /etc/ssh/sshd_config

  - sudo service ssh restart

#
# Firewall
#

  # defaults
  - sudo ufw default deny incoming
  - sudo ufw default allow outgoing

  # exceptions
  - sudo ufw allow ssh
  - sudo ufw allow http
  - sudo ufw allow https

  # start on boot
  - sed -i -e '/^ENABLED/s/^.*$/ENABLED=yes/' /etc/ufw/ufw.conf

  - sudo ufw enable

With this configuration, the root account is disabled. And I get access remote access with my dev user account.

However, MySQL installations fails with:

Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-5.7_5.7.17-0ubuntu0.16.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Cloud-init v. 0.7.8 running 'modules:final' at Sun, 29 Jan 2017 12:09:56 +0000. Up 14.23 seconds.
2017-01-29 12:11:24,114 - util.py[WARNING]: Failed to install packages: ['mysql-client', 'libmysqlclient-dev', 'mysql-server']
2017-01-29 12:11:24,125 - cc_package_update_upgrade_install.py[WARNING]: 1 failed with exceptions, re-raising the last one
2017-01-29 12:11:24,128 - util.py[WARNING]: Running module package-update-upgrade-install (<module 'cloudinit.config.cc_package_update_upgrade_install' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py'>) failed

If I don't specify any user, and perform a typical setup through apt-get the installation runs fine.

Is it not possible to setup MySQL with cloud-init while having my root account disabled? And if not, can I somehow tell cloud-init to setup my users after my packages have been installed/updated?

  • I usually setup MySQL using only a sudo account. However I am not familiar with cloud-init to give you a more meaningful answer. – Rui F Ribeiro Jan 29 '17 at 13:15
  • You're right. I've updated my question not to question that possibility. I'm able to perform these steps manually without cloud-init, and all goes well. And with cloud-init, without specifying any users it successfully installs, also. So i'm pointing toward something related to account privileges at this point...maybe a farfetched guess though. – nmdias Jan 29 '17 at 13:25
1

I was able to overcome this issue by manually setting up the mysql-server with:

runcmd:
  - sudo apt-get -y install mysql-server

Anyone with the same issue will probably also want to take a look into installing mysql non-interactively.

runcmd:
  - echo "mysql-server mysql-server/root_password password pwd" | sudo debconf-set-selections
  - echo "mysql-server mysql-server/root_password_again password pwd" | sudo debconf-set-selections

  - sudo apt-get -y install mysql-server

Solution originally posted here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.