mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Add files demonstrating cloud-init customization of Photon
Add files that demonstrate using cloud-init to customize Photon instances.
This commit is contained in:
parent
1fb8ca6c0d
commit
5f58d707ea
6 changed files with 175 additions and 0 deletions
37
photon-cloudinit/README.md
Normal file
37
photon-cloudinit/README.md
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Customizing Photon with cloud-init
|
||||
|
||||
These files provide an example of how to customize VMware Photon ([https://github.com/vmware/photon](https://github.com/vmware/photon)) using cloud-init ([https://launchpad.net/cloud-init](https://launchpad.net/cloud-init)) and the NoCloud datasource when used in conjunction with Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)). This configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin.
|
||||
|
||||
## Contents
|
||||
|
||||
* **meta-data**: This file is used by `cloud-init` and should not be modified. Vagrant will put this file in the correct place in the Photon VM(s) via the setup script that is called by `Vagrantfile`.
|
||||
|
||||
* **README.md**: This file you're reading right now.
|
||||
|
||||
* **servers.yml**: This YAML file contains configuration data for Vagrant to use to instantiate VMs. It is referenced by `Vagrantfile` when the user runs `vagrant up`. If you use a Vagrant box _other_ than "vmware/photon", or if you want more memory, more vCPUs, or more than 1 Photon VM created, then you'll need to edit this file. Otherwise, you should be able to use this file unchanged.
|
||||
|
||||
* **setup.sh**: This bash shell script prepares the Photon VM(s) to use the NoCloud datasource with `cloud-init`. The script is designed to be as idempotent as possible, but isn't guaranteed to be completely idempotent. You should not need to edit this file.
|
||||
|
||||
* **user-data**: This file is used by `cloud-init` to perform the desired customization to the Photon VM(s). You should not need to edit this file unless you wish to change the customization that is occurring. Otherwise, you can use this file unchanged.
|
||||
|
||||
* **Vagrantfile**: This file is used by Vagrant to spin up the VMs. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file in `servers.yml`.
|
||||
|
||||
## Instructions
|
||||
|
||||
These instructions assume that you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin, and that they are all working properly. Please refer to the documentation for those products for more information on installation, configuration, or troubleshooting.
|
||||
|
||||
1. If you haven't already downloaded the VMware Photon Vagrant box, use `vagrant box add vmware/photon` to download the VMware Photon Vagrant box. You can verify that the box is downloaded and ready for use with the command `vagrant box list`.
|
||||
|
||||
2. If you decided to use a different Vagrant box (something different than "vmware/photon"), you'll need to edit `servers.yml` and specify the correct box.
|
||||
|
||||
3. Put the files from the `photon-cloudinit` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository via `git clone`, or just download the specific files from the `photon-cloudinit` folder.
|
||||
|
||||
4. From a terminal window, change into the directory where you placed the files from step 3 and run `vagrant up`. Vagrant will instantiate one or more Photon VMs according to the information in `servers.yml`.
|
||||
|
||||
5. Currently, Photon VMs created by Vagrant won't perform the `cloud-init` customizations until they are rebooted after first being brought up by Vagrant. Use `vagrant ssh` to log into the Photon VM (if you created more than one by adding entries to `servers.yml`, you'll need to add the VM name to the `vagrant ssh` command). Reboot the VM using `sudo reboot -h now`.
|
||||
|
||||
6. When the Photon VM comes back up, the Docker daemon should be listening on the official Docker TCP port (2375). If you have a Docker client installed, you can run `docker -H tcp://W.X.Y.Z:2375 ps`, where "W.X.Y.Z" is the IP address assigned to the Photon VM. The command will return a list of running containers (which is most likely empty).
|
||||
|
||||
At this point, you can use the Docker client (either inside the Photon VM or from a system with connectivity to the Photon VM) to pull down images, launch images, etc.
|
||||
|
||||
Enjoy!
|
||||
57
photon-cloudinit/Vagrantfile
vendored
Normal file
57
photon-cloudinit/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Specify Vagrant version and Vagrant API version
|
||||
Vagrant.require_version ">= 1.6.0"
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
# Require 'yaml' module
|
||||
require 'yaml'
|
||||
|
||||
# Read YAML file to get VM configuration information
|
||||
# Edit servers.yml to change VM configuration details
|
||||
servers = YAML.load_file('servers.yml')
|
||||
|
||||
# Look for user-data and meta-data files in same directory
|
||||
USER_DATA = File.join(File.dirname(__FILE__), "user-data")
|
||||
META_DATA = File.join(File.dirname(__FILE__), "meta-data")
|
||||
|
||||
# Create and configure the VMs
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Use Vagrant's default insecure SSH key
|
||||
config.ssh.insert_key = false
|
||||
|
||||
# Iterate through entries in YAML file to create VMs
|
||||
servers.each do |servers|
|
||||
|
||||
# Configure the VMs per details in servers.yml
|
||||
config.vm.define servers["name"] do |srv|
|
||||
|
||||
# Don't check for box updates
|
||||
srv.vm.box_check_update = false
|
||||
|
||||
# Specify the hostname of the VM
|
||||
srv.vm.hostname = servers["name"]
|
||||
|
||||
# Specify the Vagrant box to use
|
||||
srv.vm.box = servers["box"]
|
||||
|
||||
# Disable default synced folder (not supported with Photon)
|
||||
srv.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
|
||||
# Configure VMs with RAM and CPUs per settings in servers.yml
|
||||
srv.vm.provider :vmware_fusion do |vmw|
|
||||
vmw.vmx["memsize"] = servers["ram"]
|
||||
vmw.vmx["numvcpus"] = servers["vcpu"]
|
||||
end # srv.vm.provider
|
||||
|
||||
# Configure Photon boxes to use cloud-init
|
||||
if srv.vm.box == "vmware/photon"
|
||||
srv.vm.provision "file", source: "#{USER_DATA}", destination: "/home/vagrant/user-data"
|
||||
srv.vm.provision "file", source: "#{META_DATA}", destination: "/home/vagrant/meta-data"
|
||||
srv.vm.provision "shell", path: "setup.sh", privileged: true
|
||||
end # if srv.vm.box
|
||||
end # config.vm.define
|
||||
end # servers.each
|
||||
end # Vagrant.configure
|
||||
2
photon-cloudinit/meta-data
Normal file
2
photon-cloudinit/meta-data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
instance-id: iid-local01
|
||||
local-hostname: cloudimg
|
||||
5
photon-cloudinit/servers.yml
Normal file
5
photon-cloudinit/servers.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- name: photon-01
|
||||
box: vmware/photon
|
||||
ram: 512
|
||||
vcpu: 1
|
||||
17
photon-cloudinit/setup.sh
Executable file
17
photon-cloudinit/setup.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Make directory for NoCloud cloud-init datasource
|
||||
if [ ! -d "/var/lib/cloud/seed/nocloud" ]; then
|
||||
mkdir /var/lib/cloud/seed/nocloud
|
||||
fi
|
||||
|
||||
# Put files into the correct locations for cloud-init
|
||||
# First move the user-data file, if it exists in the home directory
|
||||
if [ -f "/home/vagrant/user-data" ]; then
|
||||
mv /home/vagrant/user-data /var/lib/cloud/seed/nocloud/
|
||||
fi
|
||||
|
||||
# Next move the meta-data file, if it exists in the home directory
|
||||
if [ -f "/home/vagrant/meta-data" ]; then
|
||||
mv /home/vagrant/meta-data /var/lib/cloud/seed/nocloud/
|
||||
fi
|
||||
57
photon-cloudinit/user-data
Normal file
57
photon-cloudinit/user-data
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#cloud-config
|
||||
|
||||
groups:
|
||||
- docker: [root,vagrant]
|
||||
write_files:
|
||||
- content: |
|
||||
[Unit]
|
||||
Description=Docker TCP Socket for the API
|
||||
|
||||
[Socket]
|
||||
ListenStream=2375
|
||||
BindIPv6Only=both
|
||||
Service=docker.service
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
path: /etc/systemd/system/docker-tcp.socket
|
||||
owner: root:root
|
||||
permissions: '0644'
|
||||
- content: |
|
||||
[Unit]
|
||||
Description=Docker Socket for the API
|
||||
PartOf=docker.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=/var/run/docker.sock
|
||||
SocketMode=0660
|
||||
SocketUser=root
|
||||
SocketGroup=docker
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
path: /lib/systemd/system/docker.socket
|
||||
owner: root:root
|
||||
permissions: '0644'
|
||||
- content: |
|
||||
[Unit]
|
||||
Description=Docker Daemon
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/docker -d -H fd:// -s overlay
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
path: /lib/systemd/system/docker.service
|
||||
owner: root:root
|
||||
permissions: '0644'
|
||||
runcmd:
|
||||
- systemctl daemon-reload
|
||||
- systemctl enable docker.socket
|
||||
- systemctl enable docker-tcp.socket
|
||||
- systemctl stop docker.service
|
||||
- systemctl start docker-tcp.socket
|
||||
- systemctl start docker.socket
|
||||
Loading…
Reference in a new issue