FEATURE: Ansible module to manage Stacki hosts#846
Open
Conversation
An Ansible module for adding, editing, and removing Stacki hosts.
The module takes these parameters:
`name` - The name of the host to manage
`appliance` - The appliance used for the host
`box` - The box used for the host
`comment` - Freeform text to attach to the host
`environment` - Environment to assign the host
`groups` - List of groups to add or remove the host from. Each item has parameters:
`name` - The name of the group
`state` - If present, then a host will be added to this group.If absent, then the host will be removed from this group.
`installaction` - The install boot action for the host
`interfaces` - List of network interfaces for the host. Each item has parameters:
`channel` - Channel for this interface
`default` - Is the interface is the default for the hosts
`interface` - Device for this interface
`ip` - IP address for this interface
`name` - Logical name for this interface
`network` - Network attached to this interface
`mac` - Hardware MAC address for this interface
`module` - Device module for this interface
`options` - Module options for this interface
`vlan` - The VLAN ID for this interface
`state` - If present, then an interface will be added to the host, if needed, and options updates. If absent, then the interface will be removed from the host. If update_mac, then the interface device is used to update the mac. If update_interface, then the mac is used to update the interface device. Note: The interface device and mac are both used to match for updating an existing interface.
`osaction` - The os boot action for the host
`rack` - By convention, the number of the rack where the host is located
`rank` - By convention, the position of the host in the rack
`state` - If present, then a host will be added (if needed) and options are set to match. If absent, then the host will be removed.
Example playbook:
```
---
- hosts: localhost
tasks:
- name: Add a host
stacki_host:
name: test-backend
appliance: backend
box: default
comment: "test host"
groups:
- name: test
installaction: console
interfaces:
- default: true
interface: eth0
ip: "10.10.10.10"
mac: "00:11:22:33:44:55"
rack: "10"
rank: "4"
register: result
- name: Add host output
debug:
var: result
- name: Modify a host
stacki_host:
name: test-backend
groups:
- name: test
state: absent
installaction: default
interfaces:
- interface: eth0
state: absent
- interface: eth1
ip: "10.10.2.1"
mac: "11:22:33:44:55:66"
rack: "0"
rank: "0"
register: result
- name: Modify host output
debug:
var: result
- name: Remove a host
stacki_host:
name: test-backend
state: absent
register: result
- name: Remove host output
debug:
var: result
```
Output of the debug commands, showing the structure of the data returned:
```
TASK [Add host output] **************************************************************************
ok: [localhost] => {
"result": {
"changed": true,
"failed": false
}
}
TASK [Modify host output] ***********************************************************************
ok: [localhost] => {
"result": {
"changed": true,
"failed": false
}
}
TASK [Remove host output] ***********************************************************************
ok: [localhost] => {
"result": {
"changed": true,
"failed": false
}
}
```
langkurt
reviewed
Oct 21, 2020
| if field in ("installaction", "osaction"): | ||
| run_stack_command(f"set.host.bootaction", [ | ||
| module.params["name"], | ||
| f"type={field[:-6]}", |
langkurt
approved these changes
Oct 21, 2020
bgreenb
approved these changes
Oct 22, 2020
cjy008
reviewed
Oct 22, 2020
| @@ -0,0 +1,19 @@ | |||
| --- | |||
| - hosts: localhost | |||
| tasks: | |||
Contributor
There was a problem hiding this comment.
Is this missing the state param? Or am I just tripping?
Contributor
Author
There was a problem hiding this comment.
state defaults to present, which is the standard behavior for Ansible modules.
cjy008
approved these changes
Oct 22, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An Ansible module for adding, editing, and removing Stacki hosts.
The module takes these parameters:
Example playbook:
Output of the debug commands, showing the structure of the data returned: