https://github.com/canonical/cc-builder
An interactive CLI tool for creating a cloud-config for cloud-init based on the current machine's configuration.
https://github.com/canonical/cc-builder
Last synced: 5 months ago
JSON representation
An interactive CLI tool for creating a cloud-config for cloud-init based on the current machine's configuration.
- Host: GitHub
- URL: https://github.com/canonical/cc-builder
- Owner: canonical
- License: gpl-3.0
- Created: 2023-11-28T16:33:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T18:40:01.000Z (over 1 year ago)
- Last Synced: 2025-04-25T14:12:24.373Z (9 months ago)
- Language: Python
- Homepage:
- Size: 123 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloud Config Builder (cc-builder)
 
An interactive CLI tool for creating a cloud-config for cloud-init based on the current machine's configuration.
This tool is primarily meant as an exploratory tool to help users understand what cloud-init can do and how it can be
used to automate the creation of virtual machines or cloud instances, by providing a starting point for the cloud-config
file using a currently running machine as a reference which the user is likely already familiar with.
## Features (What can it do?)
This CLI tool gathers information from your system and generates a cloud-config file that can be used with cloud-init to create a simple image similar to the original system.
- Gather and export Apt sources from sources.list and sources.list.d/
- Gather and export Snaps installed on the system
- Gather and export manually installed Apt packages
- Gather and export detailed operating system info
- Rename the current user to the default "ubuntu" user for VM or Cloud use
- Gather and export SSHD config info (root login, password auth, etc.)
- Gather and export SSH keys for the current user (public keys, authorized_keys)
- Gather and export User info such as what shell they use and if they have sudo rights or not
## Installation
### Preferred Method: Snap
#### Installing Release Snap Binary manually
##### Installing Straight From Terminal
You can also install the snap binary directly from the terminal using the following command:
```bash
wget https://github.com/a-dubs/cc-builder/releases/download/v1.0.0/cc-builder_1.0.0_amd64.snap -O cc-builder.snap
sudo snap install --classic --dangerous cc-builder.snap
```
##### From GitHub UI
Until this tool is available in the Snap Store, you can install the snap binary manually.
Head over to the releases page and download the latest snap binary and save it as `cc-builder.snap`.
Then, install the snap binary using the following command:
```bash
sudo snap install --classic --dangerous cc-builder.snap
```
### Alternative Method: Manual Installation
1. Clone this repo
```bash
git clone https://github.com/a-dubs/cc-builder.git
```
2. Create and activate a virtual environment (optional but recommended)
* Install `pyvenv` (if not already installed)
```bash
sudo apt-get install python3-venv
```
* Create a virtual environment
```bash
python3 -m venv venv
```
* Activate the virtual environment
```bash
source venv/bin/activate
```
3. Install the dependencies
```bash
pip install .
```
4. Check if the CLI is working
```bash
cc-builder --help
```
## How to use
### Generating a cloud-config file
To generate a cloud-config file, use the `generate` command.
The `generate` command has the following CLI usage:
```bash
Usage: cc-builder [OPTIONS]
Generate a cloud-init configuration file for the current machine.
If interactive mode is enabled, the script will prompt for the necessary information to
generate the cloud-init config file and step through each configuration module and show the
cloud-config portion generated by that module.
Only -f can be used with -i/--interactive
╭─ Options ─────────────────────────────────────────────────────────────────────────────────╮
│ --interactive -i Enable interactive mode. │
│ --quiet -q Enable quiet output. Only critical errors and │
│ essential information will be displayed. │
│ --output-path -o TEXT Path to output file. [default: cloud-config.yaml] │
│ --force -f Write over output file if it already exists. │
│ --enable-hostname Enable gathering the hostname of the machine. This │
│ will cause issues unless this exact machine is being │
│ redeployed using the generated cloud-init config. │
│ --gather-public-keys Enable gathering of all public key files in the ~/.ssh │
│ directory. This will allow you to use the same public │
│ keys on the new machine as the current machine. │
│ --password TEXT Set the password for the user. WARNING: This is │
│ incredibly insecure and is stored in plaintext in the │
│ cloud-init config. │
│ --disable-apt Disable the gathering and generation of apt config. │
│ --disable-snap Disable the gathering and generation of snap config. │
│ --disable-ssh Disable the gathering and generation of ssh config. │
│ --disable-user Disable the gathering and generation of user config. │
│ --rename-to-ubuntu-user Keep the current user config but rename it to the │
│ default 'ubuntu' user. │
│ --help -h Show this message and exit. │
│ --version Show the version and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────╯
```
### Example calls for generating a cloud-config file
#### Minimal invocation
This will output a cloud-config file named cloud-config.yaml with the default settings.
```bash
cc-builder
```
#### Interactive mode
This will prompt the user for the necessary information to generate the cloud-config file and
show the cloud-config portion generated by each module along the way.
```bash
cc-builder -i
```
#### Specify custom output path
This will output a cloud-config file named cc.yaml with the default settings.
If cc.yaml already exists, the tool will not overwrite it because the `-f` flag is not passed.
```bash
cc-builder -o cc.yaml
```
#### Overwrite existing file
This will output at cloud-config at the default path with default settings but will overwrite
the cc.yaml file if it already exists.
```bash
cc-builder -o cc.yaml -f
```
#### Overwrite existing file at custom output path
This will output a cloud-config file named cc.yaml with the default settings.
But now, the tool will overwrite cc.yaml if it already exists.
```bash
cc-builder -o cc.yaml -f
```
#### Disable apt config
This will gather all other configs except for the apt sources and packages installed on the system.
And will overwrite the output file if it already exists.
```bash
cc-builder -f --disable-apt
```
#### Interactive Mode With Output Path and Force
This will prompt the user for the necessary information to generate the cloud-config file and
show the cloud-config portion generated by each module along the way. It will not prompt
for the output file path because it is already set to cc.yaml. And it will automatically
overwrite cc.yaml if it already exists.
```bash
cc-builder -i -o cc.yaml -f
```
## Submitting Feedback Via GitHub
Please feel free to open an issue against this repo for any bugs or features you'd like to see addressed.
Thanks!