Skip to content

Commit bf1e175

Browse files
authored
Merge pull request #54 from LBGarber/add-inventory-plugin
Add Instance Inventory plugin
2 parents 837890d + 5a8b32d commit bf1e175

25 files changed

+570
-16
lines changed

.mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ disallow_untyped_defs = True
44
disallow_untyped_calls = True
55
disallow_incomplete_defs = True
66
disallow_untyped_decorators = True
7-
no_strict_optional = True
7+
no_strict_optional = True

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ install: clean build
1515

1616
lint:
1717
pylint plugins
18-
mypy plugins
18+
19+
mypy plugins/modules
20+
mypy plugins/inventory
1921

2022
gendocs:
2123
mkdir -p $(DOCS_PATH)
22-
rm -f $(DOCS_PATH)/*
23-
ansible-doc-extractor --template=template/module.rst.j2 $(DOCS_PATH) plugins/modules/*.py
24+
25+
rm -rf $(DOCS_PATH)/*
26+
27+
mkdir -p $(DOCS_PATH)/modules $(DOCS_PATH)/inventory
28+
29+
ansible-doc-extractor --template=template/module.rst.j2 $(DOCS_PATH)/modules plugins/modules/*.py
30+
ansible-doc-extractor --template=template/module.rst.j2 $(DOCS_PATH)/inventory plugins/inventory/*.py
2431

2532
integration-test: $(INTEGRATION_CONFIG)
2633
ansible-test integration $(TEST_ARGS)
@@ -32,4 +39,4 @@ $(INTEGRATION_CONFIG):
3239
echo "LINODE_API_TOKEN must be set"; \
3340
exit 1; \
3441
fi
35-
echo "---\napi_token: $(LINODE_API_TOKEN)" >> $(INTEGRATION_CONFIG)
42+
echo "api_token: $(LINODE_API_TOKEN)" >> $(INTEGRATION_CONFIG)

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ PEP440 is the schema used to describe the versions of Ansible.
1919
### Modules
2020
Name | Description
2121
--- | ---
22-
[linode.cloud.firewall](https://github.com/linode/ansible_linode/blob/master/docs/firewall.rst)|Create and destroy Firewalls.
23-
[linode.cloud.firewall_info](https://github.com/linode/ansible_linode/blob/master/docs/firewall_info.rst)|Gather info about an existing Firewall.
24-
[linode.cloud.instance](https://github.com/linode/ansible_linode/blob/master/docs/instance.rst)|Create and destroy Linodes.
25-
[linode.cloud.instance_info](https://github.com/linode/ansible_linode/blob/master/docs/instance_info.rst)|Gather info about an existing Linode instance.
26-
[linode.cloud.nodebalancer](https://github.com/linode/ansible_linode/blob/master/docs/nodebalancer.rst)|Create, destroy, and configure NodeBalancers.
27-
[linode.cloud.nodebalancer_info](https://github.com/linode/ansible_linode/blob/master/docs/nodebalancer_info.rst)|Gather info about an existing NodeBalancer.
28-
[linode.cloud.object_cluster_info](https://github.com/linode/ansible_linode/blob/master/docs/object_cluster_info.rst)|Gather info about Object Storage clusters.
29-
[linode.cloud.object_keys](https://github.com/linode/ansible_linode/blob/master/docs/object_keys.rst)|Create and destroy Object Storage keys.
30-
[linode.cloud.vlan_info](https://github.com/linode/ansible_linode/blob/master/docs/vlan_info.rst)|Gather info about an existing Linode VLAN.
31-
[linode.cloud.volume](https://github.com/linode/ansible_linode/blob/master/docs/volume.rst)|Create, destroy, and attach Linode volumes.
32-
[linode.cloud.volume_info](https://github.com/linode/ansible_linode/blob/master/docs/volume_info.rst)|Gather info about an existing Linode volume.
22+
[linode.cloud.firewall](https://github.com/linode/ansible_linode/blob/master/docs/modules/firewall.rst)|Create and destroy Firewalls.
23+
[linode.cloud.firewall_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/firewall_info.rst)|Gather info about an existing Firewall.
24+
[linode.cloud.instance](https://github.com/linode/ansible_linode/blob/master/docs/modules/instance.rst)|Create and destroy Linodes.
25+
[linode.cloud.instance_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/instance_info.rst)|Gather info about an existing Linode instance.
26+
[linode.cloud.nodebalancer](https://github.com/linode/ansible_linode/blob/master/docs/modules/nodebalancer.rst)|Create, destroy, and configure NodeBalancers.
27+
[linode.cloud.nodebalancer_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/nodebalancer_info.rst)|Gather info about an existing NodeBalancer.
28+
[linode.cloud.object_cluster_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/object_cluster_info.rst)|Gather info about Object Storage clusters.
29+
[linode.cloud.object_keys](https://github.com/linode/ansible_linode/blob/master/docs/modules/object_keys.rst)|Create and destroy Object Storage keys.
30+
[linode.cloud.vlan_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/vlan_info.rst)|Gather info about an existing Linode VLAN.
31+
[linode.cloud.volume](https://github.com/linode/ansible_linode/blob/master/docs/modules/volume.rst)|Create, destroy, and attach Linode volumes.
32+
[linode.cloud.volume_info](https://github.com/linode/ansible_linode/blob/master/docs/modules/volume_info.rst)|Gather info about an existing Linode volume.
33+
34+
### Inventory
35+
Name | Description
36+
--- | ---
37+
[linode.cloud.instance](https://github.com/linode/ansible_linode/blob/master/docs/inventory/instance.rst)|Reads instance inventories from Linode.
3338

3439
<!--end collection content-->
3540

docs/inventory/instance.rst

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
.. _instance_module:
2+
3+
4+
instance
5+
========
6+
7+
.. contents::
8+
:local:
9+
:depth: 1
10+
11+
12+
Synopsis
13+
--------
14+
15+
Reads instance inventories from Linode.
16+
17+
Uses a YAML configuration file that ends with linode.(yml|yaml).
18+
19+
Linode labels are used by default as the hostnames.
20+
21+
The default inventory groups are built from groups (deprecated by Linode) and not tags.
22+
23+
24+
25+
Requirements
26+
------------
27+
The below requirements are needed on the host that executes this module.
28+
29+
- python >= 2.7
30+
- linode_api4 >= 2.0.0
31+
32+
33+
34+
Parameters
35+
----------
36+
37+
plugin (True, any, None)
38+
marks this as an instance of the 'linode' plugin
39+
40+
41+
api_token (True, any, None)
42+
The Linode account personal access token.
43+
44+
45+
regions (optional, list, [])
46+
Populate inventory with instances in this region.
47+
48+
49+
tags (optional, list, [])
50+
Populate inventory only with instances which have at least one of the tags listed here.
51+
52+
53+
types (optional, list, [])
54+
Populate inventory with instances with this type.
55+
56+
57+
strict (optional, bool, False)
58+
If ``yes`` make invalid entries a fatal error, otherwise skip and continue.
59+
60+
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
61+
62+
63+
compose (optional, dict, {})
64+
Create vars from jinja2 expressions.
65+
66+
67+
groups (optional, dict, {})
68+
Add hosts to group based on Jinja2 conditionals.
69+
70+
71+
keyed_groups (optional, list, [])
72+
Add hosts to group based on the values of a variable.
73+
74+
75+
use_extra_vars (optional, bool, False)
76+
Merge extra vars into the available variables for composition (highest precedence).
77+
78+
79+
leading_separator (optional, boolean, True)
80+
Use in conjunction with keyed_groups.
81+
82+
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
83+
84+
This is because the default prefix is "" and the default separator is "_".
85+
86+
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
87+
88+
If the group name is derived from a mapping the separator is still used to concatenate the items.
89+
90+
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
Examples
101+
--------
102+
103+
.. code-block:: yaml+jinja
104+
105+
106+
# Minimal example. `LINODE_API_TOKEN` is exposed in environment.
107+
plugin: linode.cloud.instance
108+
109+
# Example with regions, types, groups and access token
110+
plugin: linode.cloud.instance
111+
api_token: foobar
112+
regions:
113+
- eu-west
114+
types:
115+
- g5-standard-2
116+
117+
# Example with keyed_groups, groups, and compose
118+
plugin: linode.cloud.instance
119+
api_token: foobar
120+
keyed_groups:
121+
- key: tags
122+
separator: ''
123+
- key: region
124+
prefix: region
125+
groups:
126+
webservers: "'web' in (tags|list)"
127+
mailservers: "'mail' in (tags|list)"
128+
compose:
129+
ansible_port: 2222
130+
131+
132+
133+
134+
135+
136+
Status
137+
------
138+
139+
140+
141+
142+
143+
Authors
144+
~~~~~~~
145+
146+
- Luke Murphy (@decentral1se)
147+
- Lena Garber (@LBGarber)
148+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)