I’m trying to use a cloud-config.yml file to automatically configure a few basic tasks when I provision a new droplet, currently though only some steps work, others partly work, and others fail completely and looking at /var/log/clioud-init.log and /var/log/cloud-init-output.log I’m not really sure why it’s failing.
#cloud-config
packages:
- zsh
- vim-enhanced
users:
- name: jsmith
groups: wheel
shell: /usr/bin/zsh
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_authorized_keys:
- (my ssh key)
chpasswd:
list: |
jsmith:(password sanitized)
expire: False
write_files:
- path: /home/jsmith/.my.cnf
owner: "jsmith:jsmith"
permissions: 0400
content: |
[client]
user=root
password=''
runcmd:
- [ sed, -i, -e, 's/#PermitRootLogin yes/PermitRootLogin no/g', /etc/ssh/sshd_config ]
- systemctl restart sshd
For the above script only the users section runs fully, so I have a user account created trying to use a shell that failed to get installed for it login shell, I can not tell if the chpasswd failed or not as I can’t login due to ZSH failing to get installed by cloud-init. The write_files command partly works, the only thing that fails is it fails to correctly chown the file after creation (probably due to how it’s quoted?). The runcmd hook the sed command does fail, but I’m not sure if the systemcl call failed (I could have checked it’s logs to see if it was restarted but kind of lower priority to the other things).
Anyone with more experience with working with cloud-config know what I’m doing wrong or what’s going on?
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!
Hi! I attempted to replicate the issues you are seeing by creating a brand new CentOS 7 droplet using your cloud-init configuration (adding my own ssh-key and password but otherwise changing nothing).
Immediately after creation I was able to log in using the root account ssh key that I provided via the UI to watch cloud-init.log as the rest of the process completed with no errors.
I was then able to log in as the user jsmith using the key I provided.
The only thing that I can think of as a potential cause of the problem you encountered is if your ssh-key included any linebreaks that could cause the config to be parsed incorrectly.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.