Skip to content

Commit d42a458

Browse files
doc patch
1 parent ef2fb35 commit d42a458

12 files changed

+154
-269
lines changed

docs/configure-awx-aap.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ collections:
116116

117117
Once you have built your Execution Environment, which is based on the default AWX Execution Environment, you can proceed with Proxmox automation in AWX.
118118

119+
### Automating AWX NetBox/Proxmox Configuration
120+
121+
There exists a convenience script in `netbox-proxmox-automation` that's called `./setup/configure_ansible_automation.py`, and it uses `awxkit` to manage objects in AWX. It leverages the configuration that you wrote based on the sample configuration called `./conf.d/netbox_setup_objects.yml-sample`, and will save you an *immense* amount of time.
122+
123+
Usage (inital setup):
124+
125+
```
126+
shell$ cd /path/to/netbox-proxmox-automation/setup
127+
128+
shell$ deactivate
129+
130+
shell$ rm -rf venv
131+
132+
shell$ python3 -m venv venv
133+
134+
shell$ source venv/bin/activate
135+
136+
shell$ pip install -r requirements.txt
137+
```
138+
139+
Then make sure that you've made a copy of `../conf.d/netbox_setup_objects.yml-sample` and seasoned it to taste before proceeding.
140+
141+
Usage (creation) of AWX objects that will be used for NetBox/Proxmox automation: `./configure_ansible_automation.py create --config /path/to/netbox-setup-objects.yml`
142+
143+
Usage (removal) of *all* AWX objects that would be used for NetBox/Proxmox automation (*proceed with caution!*): `./configure_ansible_automation.py destroy --config /path/to/netbox-setup-objects.yml`
144+
145+
### Manual AWX NetBox/Proxmox Configuration
146+
147+
*This is not required if you have been able to run the convenience script, `./configure_ansible_automation.py`.*
148+
119149
#### Add NetBox and Proxmox Credential Types to AWX
120150

121151
Navigate to Administration > Credential Types in AWX, and create a credential type called 'NetBox Proxmox Creds'.

docs/configure-flask-application.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
## Configure Flask Application (Python)
22

3-
*You only need to do this configuration step if you intend to use the example Flask application to handle your Proxmox automation.*
3+
*You only need to do this configuration step if you intend to use the Flask application to handle your Proxmox automation.*
44

55
Open a shell on your local system. *Do not* run these commands as the 'root' user. The following commands should run on MacOS, Linux, and UNIX-like systems; you will need to run these commands during initial installation or upgrades of `netbox-proxmox-automation`.
66

77
```
8-
shell$ cd /path/to/netbox-proxmox-automation/example-netbox-webhook-flask-app
8+
shell$ cd /path/to/netbox-proxmox-automation/netbox-event-driven-automation-flask-app
99
1010
shell$ deactivate # this will fail if there is no configured venv
1111
@@ -28,7 +28,7 @@ shell$
2828
With each usage of `netbox-proxmox-automation`, make sure that you enter `venv` before running any Ansible commands. Else this automation will not work.
2929

3030
```
31-
shell$ cd /path/to/netbox-proxmox-automation/example-netbox-webhook-flask-app
31+
shell$ cd /path/to/netbox-proxmox-automation/netbox-event-driven-automation-flask-app
3232
3333
shell$ source venv/bin/activate
3434
@@ -38,7 +38,7 @@ shell$ source venv/bin/activate
3838
When in `venv`, you will need to create `app_config.yml`.
3939

4040
```
41-
(venv) shell$ cd /path/to/netbox-proxmox-automation/example-netbox-webhook-flask-app
41+
(venv) shell$ cd /path/to/netbox-proxmox-automation/netbox-event-driven-automation-flask-app
4242
4343
(venv) shell$ cp -pi app_config.yml-sample app_config.yml
4444
```
@@ -58,5 +58,28 @@ Press CTRL+C to quit
5858
* Debugger PIN: XXX-XXX-XXX
5959
```
6060

61-
The above `flask` command will start the Flask application on port 8000 (or whatever you specify with the `-p` argument) and will bind on the IP address (or IP addresses) that were specified with the `-h` argument. In this case, we used 0.0.0.0 with the `-h` argument, so the Flask application will listen on all interfaces. The `--debug` argument indicates that we will run a single-threaded web service and that we will show output to stdout. *You will want to use `gunicorn.py` or some other WSGI server to run the Flask application in production.*
61+
The above `flask` command will start the Flask application on port 8000 (or whatever you specify with the `-p` argument) and will bind on the IP address (or IP addresses) that were specified with the `-h` argument. In this case, we used 0.0.0.0 with the `-h` argument, so the Flask application will listen on all interfaces. The `--debug` argument indicates that we will run a single-threaded web service and that we will show output to stdout.
62+
63+
*You will want to use `gunicorn.py` or some other WSGI server to run the Flask application in production.* This is documented [here](https://flask.palletsprojects.com/en/stable/deploying/gunicorn/), but here's an annotated version of how to use gunicorn to run netbox-event-driven-automation-flask-app.
64+
65+
1. Make sure that you are in the netbox-event-driven-automation-flask-app directory: `cd /path/to/netbox-proxmox-automation/netbox-event-driven-automation-flask-app`
66+
67+
2. Leave `venv`: `deactivate`
68+
69+
3. Remove existing `venv`: `rm -rf venv`
70+
71+
4. Create new `venv`: `python3 -m venv venv`
72+
73+
5. Enter new `venv`: `source venv/bin/activate`
74+
75+
6. `pip` install requirements: `pip install -r requirements.txt`
76+
77+
7. Run the application: `gunicorn -w 4 -b 0.0.0.0:9000 'app:app'`, or season this command to taste for how you want to bind, including your preferred port number for listening.
78+
79+
You can then start using `netbox-event-driven-automation-flask-app` from NetBox!
80+
81+
Granted, there are myriad ways to do this, including using NGINX to proxy connections to this Flask application, but that's an exercise that's left up to the reader for the time being.
82+
83+
84+
6285

docs/index.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,36 @@
22

33
[NetBox](https://github.com/netbox-community/netbox) is the world's most popular Network Source of Truth (NSoT) with tens of thousands of installations globally. It is used extensively for documenting/modeling networks (network devices, virtual machines, etc), and also provides a great IPAM solution. [Proxmox](https://www.proxmox.com/en/) is a freely available virtualization technology that allows you to deploy virtual machines (VMs) at scale, and perhaps in a clustered configuration. Proxmox has approximately [900,000 hosts and more than 130,000 users in its open source community](https://www.proxmox.com/en/about/press-releases/proxmox-virtual-environment-8-1).
44

5-
When you think of the challenges of a widely used network documentation solution and a widely used virtualization technology, this implementation is an integration between virtual machine documentation (NetBox) and the automation of Proxmox virtual machine (VM) deployment and configuration.
5+
When you think of the challenges of a widely used network documentation solution and a widely used virtualization technology, this implementation is an integration between virtual machine documentation (NetBox) and the automation of Proxmox virtual machine (VM) and container (LXC) deployment and configuration.
66

7-
This automation handles creation, removal, and changes of/to Proxmox VMs. The underlying automation uses [webhooks](https://demo.netbox.dev/static/docs/additional-features/webhooks/) and [event rules](https://netboxlabs.com/docs/netbox/en/stable/features/event-rules/) in NetBox. When you induce a change in NetBox, this will set the desired VM state(s) in Proxmox.
7+
This automation handles creation, removal, and changes of/to Proxmox VMs *and* LXCs. The underlying automation uses [webhooks](https://demo.netbox.dev/static/docs/additional-features/webhooks/) and [event rules](https://netboxlabs.com/docs/netbox/en/stable/features/event-rules/) in NetBox. When you induce a change in NetBox, this will set the desired VM state(s) in Proxmox.
88

9-
When you create/update/delete VM objects in NetBox, the following will take place in Proxmox:
9+
When you create/update/delete VM objects (for Proxmox VM) in NetBox, the following will take place in Proxmox:
1010

11-
- when you create a VM object in NetBox (name, status == Staged, chosen Proxmox VM template name), this will clone a VM in Proxmox of the same name, from the defined template
11+
- when you create a VM object in NetBox (name, status == Staged, VM Type == Virtual Machine, chosen Proxmox VM template name), this will clone a VM in Proxmox of the same name, from the defined template
1212
- when you add a SSH key to a NetBox VM object (status == Staged), a SSH key will be added to the VM settings in Proxmox
1313
- when you add a primary IP address to a NetBox VM object (status == Staged), this will update the VM settings in Proxmox for ipconfig0
1414
- when you add or resize VM disks (scsi0 - scsiN) for a NetBox VM object (status == Staged), this will:
15-
- resize scsi0 on the Proxmox VM to the size that was defined in NetBox
16-
- create scsi1 - scsiN on the Proxmox VM and set them to their specified sizes
17-
- resize scsi1 - scsiN on the Proxmox VM and resize them to their specified sizes (*NOTE: Proxmox does not allow you to shrink disks!*)
15+
- resize scsi0 on the Proxmox VM to the size that was defined in NetBox
16+
- create scsi1 - scsiN on the Proxmox VM and set them to their specified sizes
17+
- resize scsi1 - scsiN on the Proxmox VM and resize them to their specified sizes (*NOTE: Proxmox does not allow you to shrink disks!*)
1818
- when you remove a disk or disks from a NetBox VM object, this will remove the corresponding disks from the Proxmox VM (*NOTE: this does not include scsi0 as that is the OS disk*)
1919

2020
Further:
2121

2222
- when you set a VM's state to 'Active' in NetBox, this will start a VM in Proxmox
2323
- when you set a VM's state to 'Offline' in NetBox, this still stop a VM in Proxmox
2424
- when you remove a VM from NetBox, this will stop and remove a VM in Proxmox.
25+
26+
When you create/update/delete VM objects (for Proxmox LXC) in NetBox, the following will take place in Proxmox:
27+
28+
- when you create a VM object in NetBox (name, status == Staged, VM Type == LXC Container, chosen Proxmox VM template name, defined public SSH key), this will clone a LXC in Proxmox of the same name, from the defined template, and will also set the public SSH key (*NOTE: In LXC, you can only set the public SSH key once, and that's during the cloning process!*)
29+
- when you add a primary IP address to a NetBox VM object (status == Staged), this will update the VM settings in Proxmox for netif for the LXC
30+
- when you add or resize the VM disk (rootfs) for a NetBox VM object (status == Staged), this will:
31+
- resize rootfs on the Proxmox LXC to the size that was defined in NetBox
32+
33+
Further:
34+
35+
- when you set a VM's state to 'Active' in NetBox, this will start a LXC in Proxmox
36+
- when you set a VM's state to 'Offline' in NetBox, this still stop a LXC in Proxmox
37+
- when you remove a VM from NetBox, this will stop and remove a LXC in Proxmox.

docs/netbox-customization.md

Lines changed: 63 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
You will need to do some customization to NetBox to define the underlying Proxmox VM configuration(s). This section covers the custom field choices and custom fields that you'll need to create in NetBox -- in order for you to facilitate automation.
44

5-
### Custom Field Choices (for Proxmox VM templates and storage)
5+
### Custom Field Choices (for Proxmox VM and LXC automation)
66

7-
In the NetBox UI, you will need to create the following custom field choices
7+
You will need to perform some customization in NetBox before you can start automating Proxmox VMs and LXCs.
88

9-
1. `proxmox-node` will be used to correlate a Proxmox node to the Proxmox VM that you will provision
10-
2. `proxmox-vm-templates` will be used to correlate a Proxmox VM template with the Proxmox VM that you will provision
11-
3. `proxmox-vm-storage` will be used to correlate an underlying Proxmox VM storage volume with the Proxmox VM you will provision
12-
13-
#### Automated NetBox Objects and Custom Fields Creation
14-
15-
If you'd prefer to manually create the webhook and event rules in NetBox, you can skip to the next section. Otherwise, proceed with the following to automate the creation of the webhook and event rules in NetBox.
9+
#### Automated NetBox Objects and the Creation of Custom Field Choices and Custom Fields
1610

1711
`netbox-proxmox-automation` version 1.1.0 and newer ships with a convenience script, `netbox_setup_objects_and_custom_fields.py`, that when used alongside a configuration file of your choice, will greatly simplify this process. In the case of AWX/Tower/AAP, `netbox_setup_objects_and_custom_fields.py` will query your AWX/Tower/AAP instance for project and template(s) information; this information will then be used to create the corresponding webhooks and event rules in NetBox.
1812

@@ -56,92 +50,65 @@ shell$ source venv/bin/activate
5650
(venv) shell$ ./netbox_setup_objects_and_custom_fields.py --config /path/to/your/configuration.yml
5751
```
5852

59-
Then verify that everything has been created. You can skip the rest of this document if so.
60-
61-
62-
If *not* using automation, in the NetBox UI, navigate to Customization > Custom Field Choices
63-
64-
#### proxmox-node
65-
66-
Create custom field choices for Proxmox VM Node(s). When you click the '+' button, you will be presented with an Edit screen. Fill the form as shown below. Note that your choices will represent a list of Proxmox cluster nodes. You will need to login to the Proxmox UI to get the list of Proxmox cluster nodes.
67-
68-
![Screenshot of Proxmox VM Cluster Nodes Edit screen](./images/proxmox-cluster-nodes-edit.png)
69-
70-
When you are done, your Custom Field Choices for Proxmox VM node(s) should look like this.
71-
72-
![Screenshot of Proxmox VM Cluster Nodes View screen](./images/proxmox-cluster-nodes-saved.png)
73-
74-
75-
#### proxmox-vm-templates
76-
77-
Create custom field choices for Proxmox VM Templates. When you click the '+' button, you will be presented with an Edit screen. Fill the form as shown below. Note that your choices will have a (Proxmox) VMID to name-of-template mapping. You will need to login to the Proxmox UI to get the VMID to name-of-template mappings.
78-
79-
![Screenshot of Proxmox VM Templates Edit screen](./images/proxmox-vm-templates-edit.png)
80-
81-
When you are done, your Custom Field Choices for Proxmox VM templates should look like this.
82-
83-
![Screenshot of Proxmox VM Templates View screen](./images/proxmox-vm-templates-saved.png)
84-
85-
86-
#### proxmox-vm-storage
87-
88-
Create custom field choices for Proxmox VM Storage. When you click the '+' button, you will be presented with an Edit screen. Fill the form as shown below. Note that your choices will represent the name/value of each Proxmox storage volume. You will need to login to the Proxmox UI to get a list of Proxmox storage volumes.
89-
90-
![Screenshot of Proxmox VM Storage Edit screen](./images/proxmox-vm-storage-edit.png)
91-
92-
When you are done, your Custom Field Choices for Proxmox VM storage should look like this.
93-
94-
![Screenshot of Proxmox VM Storage View screen](./images/proxmox-vm-storage-saved.png)
95-
96-
97-
### NetBox Customization: Custom Fields (for Proxmox VMs)
98-
99-
In the NetBox UI, you will need to create a series of custom fields, as noted below.
100-
101-
1. `proxmox_node` will be used to correlate a Proxmox cluster node with the Proxmox VM that you want to create
102-
2. `proxmox_vm_template` will be used to correlate a Proxmox VM template with the Proxmox VM that you want to create
103-
3. `proxmox_vm_storage` will be used to correlate a Proxmox VM storage volume with the Proxmox VM that you want to create
104-
4. `proxmox_disk_storage_volume` will be used to correlate a Proxmox VM storage volume with each Proxmox VM disk that you want to create
105-
5. `proxmox_public_ssh_key` will be used to assign a public SSH key that you will use to login to a Proxmox VM
106-
6. `proxmox_vmid` will be used to document the Proxmox `vmid` that was created when the Proxmox VM was created
107-
108-
In the NetBox UI, navigate to Customization > Custom Fields
109-
110-
111-
#### proxmox_node
112-
113-
Create a custom field for Proxmox Node. It will be called `proxmox_node`. Here is what `proxmox_node` should look like after you've made your changes.
114-
115-
![Screenshot of proxmox_node in NetBox UI](./images/proxmox-node.png)
116-
117-
118-
#### proxmox_vm_template
119-
120-
Create a custom field for Proxmox VM template. It will be called `proxmox_vm_template`. Here is what `proxmox_vm_template` should look like after you've made your changes.
121-
122-
![Screenshot of proxmox_vm_template in NetBox UI](./images/proxmox-vm-template.png)
123-
124-
#### proxmox_vm_storage
125-
126-
Create a custom field for Proxmox VM storage. It will be called `proxmox_vm_storage`. Here is what `proxmox_vm_storage` should look like after you've made your changes.
127-
128-
![Screenshot of proxmox_vm_storage in NetBox UI](./images/proxmox-vm-storage.png)
129-
130-
#### proxmox_disk_storage_volume
131-
132-
Create a custom field for Proxmox disk storage volume. It will be called `proxmox_disk_storage_volume`. Here is what `proxmox_disk_storage_volume` should look like after you've made your changes.
133-
134-
![Screenshot of proxmox_disk_storage_volume in NetBox UI](./images/proxmox-disk-storage-volume.png)
135-
136-
#### proxmox_public_ssh_key
137-
138-
Create a custom field for Proxmox VM public SSH key. It will be called `proxmox_public_ssh_key`. Here is what `proxmox_public_ssh_key` should look like after you've made your changes.
139-
140-
![Screenshot of proxmox_public_ssh_key in NetBox UI](./images/proxmox-public-ssh-key.png)
141-
142-
#### proxmox_vmid
143-
144-
Create a custom field for Proxmox VMID. It will be called `proxmox_vmid`. Here is what `proxmox_vmid` should look like after you've made your changes. *Note that `proxmox_vmid` is set automatically during the Proxmox VM provisioning process. Any VMID that you specified will be discarded.*
53+
Then verify that everything has been created. In the end, you should have Custom Fields for the following.
54+
55+
- proxmox_node:
56+
- Object types: Virtual Machine
57+
- Label: Proxmox node
58+
- Group name: Proxmox (common)
59+
- Type: Selection
60+
- proxmox_vm_type:
61+
- Object types: Virtual Machine
62+
- Label: Proxmox VM Type
63+
- Group name: Proxmox (common)
64+
- Type: Selection
65+
- proxmox_vmid:
66+
- Object types: Virtual Machine
67+
- Label: Proxmox Virtual machine ID (vmid)
68+
- Group name: Proxmox (common)
69+
- Type: Text
70+
- proxmox_vm_storage:
71+
- Object types: Virtual Machine
72+
- Label: Proxmox VM Storage
73+
- Group name: Proxmox (common)
74+
- Type: Selection
75+
- proxmox_public_ssh_key:
76+
- Object types: Virtual Machine
77+
- Label: Proxmox public SSH key
78+
- Group name: Proxmox (common)
79+
- Type: Text (long)
80+
- proxmox_lxc_templates:
81+
- Object types: Virtual Machine
82+
- Label: Proxmox LXC Templates
83+
- Group name: Proxmox LXC
84+
- Type: Selection
85+
- proxmox_disk_storage_volume:
86+
- Object types: Virtual Disk
87+
- Label: Proxmox Disk Storage Volume
88+
- Group name: Proxmox VM
89+
- Type: Selection
90+
- proxmox_vm_templates:
91+
- Object types: Virtual Machine
92+
- Label: Proxmox VM Templates
93+
- Group name: Proxmox VM
94+
- Type: Selection
95+
96+
And you have Custom Field Choices for the following:
97+
98+
- proxmox-cluster-nodes: used by `proxmox_node` custom field
99+
- Choices: available Proxmox nodes
100+
- Default: first "discovered" Proxmox node
101+
- proxmox-lxc-templates: used by `proxmox_lxc_templates` custom field
102+
- Choices: "discovered" available Proxmox LXC images
103+
- Default: first "discovered" Proxmox LXC image
104+
- proxmox-vm-storage: used by `proxmox_vm_storage` custom field
105+
- Choices: "discovered" Proxmox storage volumes
106+
- Default: first "discovered" Proxmox storage volume
107+
- proxmox-vm-templates: used by `proxmox_vm_templates` custom field
108+
- Choices: "discovered" Proxmox VM templates
109+
- Default: first "discovered" Proxmox VM template, based on lowest discovered vmid
110+
- proxmox-vm-type: used by `proxmox_vm_type`
111+
- Choices: Virtual Machine, LXC Container
112+
- Default: Virtual Machine
145113

146-
![Screenshot of proxmox_vmid in NetBox UI](./images/proxmox-vmid.png)
147114

0 commit comments

Comments
 (0)