Skip to content

Commit

Permalink
Use multiple YAML documents for inventory plugin examples (#9551)
Browse files Browse the repository at this point in the history
* Use multiple YAML documents for inventory plugin examples.

* Add ignore.txt entries.

* Delete no longer needed ignore.txt files.

* Fix typo.

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
(cherry picked from commit 3f7ea60)
  • Loading branch information
felixfontein authored and patchback[bot] committed Jan 8, 2025
1 parent 8b56b6d commit afc4dc2
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 44 deletions.
2 changes: 2 additions & 0 deletions plugins/inventory/gitlab_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@
'''

EXAMPLES = '''
---
# gitlab_runners.yml
plugin: community.general.gitlab_runners
host: https://gitlab.com
---
# Example using constructed features to create groups and set ansible_host
plugin: community.general.gitlab_runners
host: https://gitlab.com
Expand Down
5 changes: 5 additions & 0 deletions plugins/inventory/iocage.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,25 @@
'''

EXAMPLES = '''
---
# file name must end with iocage.yaml or iocage.yml
plugin: community.general.iocage
host: 10.1.0.73
user: admin
---
# user is not required if iocage is running on localhost (default)
plugin: community.general.iocage
---
# run cryptography without legacy algorithms
plugin: community.general.iocage
host: 10.1.0.73
user: admin
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
---
# enable cache
plugin: community.general.iocage
host: 10.1.0.73
Expand All @@ -93,6 +97,7 @@
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
cache: true
---
# see inventory plugin ansible.builtin.constructed
plugin: community.general.iocage
host: 10.1.0.73
Expand Down
5 changes: 5 additions & 0 deletions plugins/inventory/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@
'''

EXAMPLES = r'''
---
# Minimal example. `LINODE_ACCESS_TOKEN` is exposed in environment.
plugin: community.general.linode
---
# You can use Jinja to template the access token.
plugin: community.general.linode
access_token: "{{ lookup('ini', 'token', section='your_username', file='~/.config/linode-cli') }}"
# For older Ansible versions, you need to write this as:
# access_token: "{{ lookup('ini', 'token section=your_username file=~/.config/linode-cli') }}"
---
# Example with regions, types, groups and access token
plugin: community.general.linode
access_token: foobar
Expand All @@ -96,6 +99,7 @@
types:
- g5-standard-2
---
# Example with keyed_groups, groups, and compose
plugin: community.general.linode
access_token: foobar
Expand All @@ -114,6 +118,7 @@
ansible_ssh_host: ipv4[0]
ansible_port: 2222
---
# Example where control traffic limited to internal network
plugin: community.general.linode
access_token: foobar
Expand Down
3 changes: 3 additions & 0 deletions plugins/inventory/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@
'''

EXAMPLES = '''
---
# simple lxd.yml
plugin: community.general.lxd
url: unix:/var/snap/lxd/common/lxd/unix.socket
---
# simple lxd.yml including filter
plugin: community.general.lxd
url: unix:/var/snap/lxd/common/lxd/unix.socket
state: RUNNING
---
# simple lxd.yml including virtual machines and containers
plugin: community.general.lxd
url: unix:/var/snap/lxd/common/lxd/unix.socket
Expand Down
4 changes: 3 additions & 1 deletion plugins/inventory/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,20 @@
- 'TODO: add OS fingerprinting'
'''
EXAMPLES = '''
---
# inventory.config file in YAML format
plugin: community.general.nmap
strict: false
address: 192.168.0.0/24
---
# a sudo nmap scan to fully use nmap scan power.
plugin: community.general.nmap
sudo: true
strict: false
address: 192.168.0.0/24
---
# an nmap scan specifying ports and classifying results to an inventory group
plugin: community.general.nmap
address: 192.168.0.0/24
Expand Down
5 changes: 5 additions & 0 deletions plugins/inventory/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
'''

EXAMPLES = '''
---
# Minimal example which will not gather additional facts for QEMU/LXC guests
# By not specifying a URL the plugin will attempt to connect to the controller host on port 8006
# my.proxmox.yml
Expand All @@ -148,6 +149,7 @@
# an example where this is set to `false` and where ansible_host is set with `compose`.
want_proxmox_nodes_ansible_host: true
---
# Instead of login with password, proxmox supports api token authentication since release 6.2.
plugin: community.general.proxmox
user: ci@pve
Expand All @@ -164,6 +166,7 @@
32643131386134396336623736393634373936356332623632306561356361323737313663633633
6231313333666361656537343562333337323030623732323833
---
# More complete example demonstrating the use of 'want_facts' and the constructed options
# Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true'
# my.proxmox.yml
Expand All @@ -186,6 +189,7 @@
# an example where this is set to `false` and where ansible_host is set with `compose`.
want_proxmox_nodes_ansible_host: true
---
# Using the inventory to allow ansible to connect via the first IP address of the VM / Container
# (Default is connection by name of QEMU/LXC guests)
# Note: my_inv_var demonstrates how to add a string variable to every host used by the inventory.
Expand All @@ -203,6 +207,7 @@
my_inv_var_2: >
"my_var_2_value"
---
# Specify the url, user and password using templating
# my.proxmox.yml
plugin: community.general.proxmox
Expand Down
3 changes: 3 additions & 0 deletions plugins/inventory/scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
# scaleway_inventory.yml file in YAML format
# Example command line: ansible-inventory --list -i scaleway_inventory.yml
---
# use hostname as inventory_hostname
# use the private IP address to connect to the host
plugin: community.general.scaleway
Expand All @@ -91,6 +92,7 @@
ansible_host: private_ip
state: state
---
# use hostname as inventory_hostname and public IP address to connect to the host
plugin: community.general.scaleway
hostnames:
Expand All @@ -100,6 +102,7 @@
variables:
ansible_host: public_ip.address
---
# Using static strings as variables
plugin: community.general.scaleway
hostnames:
Expand Down
15 changes: 8 additions & 7 deletions plugins/inventory/virtualbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
'''

EXAMPLES = '''
---
# file must be named vbox.yaml or vbox.yml
simple_config_file:
plugin: community.general.virtualbox
settings_password_file: /etc/virtulbox/secrets
query:
logged_in_users: /VirtualBox/GuestInfo/OS/LoggedInUsersList
compose:
ansible_connection: ('indows' in vbox_Guest_OS)|ternary('winrm', 'ssh')
plugin: community.general.virtualbox
settings_password_file: /etc/virtualbox/secrets
query:
logged_in_users: /VirtualBox/GuestInfo/OS/LoggedInUsersList
compose:
ansible_connection: ('indows' in vbox_Guest_OS)|ternary('winrm', 'ssh')
---
# add hosts (all match with minishift vm) to the group container if any of the vms are in ansible_inventory'
plugin: community.general.virtualbox
groups:
Expand Down
14 changes: 0 additions & 14 deletions tests/sanity/ignore-2.13.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/sanity/ignore-2.13.txt.license

This file was deleted.

16 changes: 0 additions & 16 deletions tests/sanity/ignore-2.14.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/sanity/ignore-2.14.txt.license

This file was deleted.

8 changes: 8 additions & 0 deletions tests/sanity/ignore-2.15.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.azure-pipelines/scripts/publish-codecov.py replace-urlopen
plugins/inventory/gitlab_runners.py yamllint:unparsable-with-libyaml
plugins/inventory/iocage.py yamllint:unparsable-with-libyaml
plugins/inventory/linode.py yamllint:unparsable-with-libyaml
plugins/inventory/lxd.py yamllint:unparsable-with-libyaml
plugins/inventory/nmap.py yamllint:unparsable-with-libyaml
plugins/inventory/proxmox.py yamllint:unparsable-with-libyaml
plugins/inventory/scaleway.py yamllint:unparsable-with-libyaml
plugins/inventory/virtualbox.py yamllint:unparsable-with-libyaml
plugins/lookup/dependent.py validate-modules:unidiomatic-typecheck
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
plugins/modules/homectl.py import-3.11 # Uses deprecated stdlib library 'crypt'
Expand Down
8 changes: 8 additions & 0 deletions tests/sanity/ignore-2.16.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
plugins/inventory/gitlab_runners.py yamllint:unparsable-with-libyaml
plugins/inventory/iocage.py yamllint:unparsable-with-libyaml
plugins/inventory/linode.py yamllint:unparsable-with-libyaml
plugins/inventory/lxd.py yamllint:unparsable-with-libyaml
plugins/inventory/nmap.py yamllint:unparsable-with-libyaml
plugins/inventory/proxmox.py yamllint:unparsable-with-libyaml
plugins/inventory/scaleway.py yamllint:unparsable-with-libyaml
plugins/inventory/virtualbox.py yamllint:unparsable-with-libyaml
plugins/lookup/dependent.py validate-modules:unidiomatic-typecheck
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
plugins/modules/homectl.py import-3.11 # Uses deprecated stdlib library 'crypt'
Expand Down

0 comments on commit afc4dc2

Please sign in to comment.