Added cloud-init KB and examples

This commit is contained in:
Michele Cereda
2022-11-27 11:56:25 +01:00
parent e1832bd9f9
commit 09007d76a5
4 changed files with 76 additions and 25 deletions

View File

@@ -4,7 +4,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
args:
@@ -13,16 +13,17 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/markdownlint/markdownlint
rev: v0.11.0
rev: v0.12.0
hooks:
- id: markdownlint
args:
- -r "~MD013" # ignore line-length rule
- repo: https://github.com/ansible-community/ansible-lint
rev: v6.1.0
rev: v6.9.0
hooks:
- id: ansible-lint
exclude: ^cloud-init/
- repo: https://github.com/hadolint/hadolint
rev: v2.10.0
rev: v2.12.1-beta
hooks:
- id: hadolint

21
cloud-init/base.yaml Normal file
View File

@@ -0,0 +1,21 @@
#cloud-config
# Sources:
# - https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config
# Upgrade the instance
# Deactivated as this could take a long time if the image is old
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#run-apt-or-yum-upgrade
package_upgrade: false
package_reboot_if_required: false
# Install required packages
# This will always update the list of packages, regardless of package_update's value.
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages
packages:
- jq
- nc
- traceroute
- unzip

View File

@@ -0,0 +1,37 @@
#cloud-config
# Sources:
# - https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config
# Add the Docker repository
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#yum-add-repo
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#adding-a-yum-repository
#
# Got from the official installation guide at
# https://docs.docker.com/engine/install/rhel/#install-using-the-repository :
# yum install -y yum-utils && \
# yum-config-manager --add-repo \
# https://download.docker.com/linux/rhel/docker-ce.repo && \
# cat /etc/yum.repos.d/docker-ce.repo
yum_repos:
docker-ce:
name: Docker CE Stable - $basearch
enabled: true
baseurl: https://download.docker.com/linux/rhel/$releasever/$basearch/stable
priority: 1
gpgcheck: true
gpgkey: https://download.docker.com/linux/rhel/gpg
# Install required packages
# This will always update the list of packages, regardless of package_update's value.
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages
#
# docker-ce already depends on docker-ce-cli and containerd.io
packages:
- docker-ce
# Enable and start the service after installation
runcmd:
- systemctl daemon-reload
- systemctl enable --now docker.service

View File

@@ -36,24 +36,15 @@ sudo cloud-init clean
# Re-run everything.
sudo cloud-init init
# Check the user scripts.
ls '/var/lib/cloud/instance/scripts'
```
```yaml
#cloud-config
# Sources:
# - https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config
# Add the Docker repository
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#yum-add-repo
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#adding-a-yum-repository
#
# Got from the official installation guide at
# https://docs.docker.com/engine/install/rhel/#install-using-the-repository :
# yum install -y yum-utils && \
# yum-config-manager --add-repo \
# https://download.docker.com/linux/rhel/docker-ce.repo && \
# cat /etc/yum.repos.d/docker-ce.repo
yum_repos:
docker-ce:
name: Docker CE Stable - $basearch
@@ -64,17 +55,10 @@ yum_repos:
gpgkey: https://download.docker.com/linux/rhel/gpg
# Upgrade the instance
# Deactivated as this could take a long time if the image is old
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#run-apt-or-yum-upgrade
package_upgrade: false
package_reboot_if_required: false
package_upgrade: true
package_reboot_if_required: true
# Install required packages
# This will always update the list of packages, regardless of package_update's value.
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages
#
# docker-ce already depends on docker-ce-cli and containerd.io
packages:
- docker-ce
@@ -162,22 +146,30 @@ merge_type: 'list(append)+dict(recurse_array)+str()'
- [Merging User-Data sections]
- [cloud-init multipart encoding issues]
- [Test cloud-init with a multipass container]
- [Mime Multi Part Archive] format
- [Docker cloud init example]
## Sources
- [Debugging cloud-init]
- [Tutorial]
- [Cloud-Init configuration merging]
- [Terraform's cloud-init provider]
<!-- cloud-init documentation -->
[debugging cloud-init]: https://cloudinit.readthedocs.io/en/latest/topics/debugging.html
[examples]: https://cloudinit.readthedocs.io/en/latest/topics/examples.html
[merging user-data sections]: https://cloudinit.readthedocs.io/en/latest/topics/merging.html
[modules]: https://cloudinit.readthedocs.io/en/latest/topics/modules.html
[mime multi part archive]: https://cloudinit.readthedocs.io/en/latest/topics/format.html#mime-multi-part-archive
[tutorial]: https://cloudinit.readthedocs.io/en/latest/topics/tutorial.html
[website]: https://cloud-init.io/
<!-- internal references -->
[docker cloud init example]: ../cloud-init/docker.yaml
<!-- external references -->
[cloud-init configuration merging]: https://jen20.dev/post/cloudinit-configuration-merging/
[cloud-init multipart encoding issues]: https://github.com/hashicorp/terraform/issues/4794
[test cloud-init with a multipass container]: https://medium.com/open-devops-academy/test-cloud-init-with-a-multipass-containers-e3e3bb740604
[terraform's cloud-init provider]: https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs/data-sources/cloudinit_config