Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter hooks to inventory plugin iocage #9650

Open
1 task done
vbotka opened this issue Jan 30, 2025 · 1 comment
Open
1 task done

Add parameter hooks to inventory plugin iocage #9650

vbotka opened this issue Jan 30, 2025 · 1 comment
Labels
feature This issue/PR relates to a feature request inventory inventory plugin plugins plugin (any type)

Comments

@vbotka
Copy link
Contributor

vbotka commented Jan 30, 2025

Summary

(Use case: root access on the iocage host is not needed to create inventory.)

The parameter hooks is a list of files inside a jail that provide configuration parameters for the inventory. For example,

hooks:
  - /var/db/dhclient-hook.address.epair0b

may provide the IP address of the interface epair0b, obtained by dhclient. Then, the inventory plugin creates the variable iocage_hooks

iocage_hooks:
  - 10.1.0.130

This can be used to compose ansible_host

compose:
  ansible_host: iocage_hooks.0

Privilege escalation is not needed if the file /var/db/dhclient-hook.address.epair0b is readable by the user logged on to the iocage host.

As a side note: the file in the above example is created by this hook

shell> cat /etc/dhclient-exit-hooks 
case "$reason" in
    "BOUND"|"REBIND"|"REBOOT"|"RENEW")
    echo $new_ip_address > /var/db/dhclient-hook.address.$interface
    ;;
esac

Issue Type

Feature Idea

Component Name

plugins/inventory/iocage.py

Additional Information

Given the jails (as root at iocage host 10.1.0.18)

shell> iocage list -lh
38	test_101	off	up	jail	13.4-RELEASE-p2	epair0b|10.1.0.130	-	ansible_client	no
39	test_102	off	up	jail	13.4-RELEASE-p2	epair0b|10.1.0.245	-	ansible_client	no
40	test_103	off	up	jail	13.4-RELEASE-p2	epair0b|10.1.0.180	-	ansible_client	no

the configuration

shell> cat iocage.yml
plugin: community.general.iocage
host: 10.1.0.18
user: admin
hooks:
  - /var/db/dhclient-hook.address.epair0b
compose:
  ansible_host: iocage_hooks.0
groups:
  test_01: inventory_hostname.startswith('test')

gives

shell> ansible-inventory -i iocage.yml --list --yaml
all:
  children:
    test_01:
      hosts:
        test_101:
          ansible_host: 10.1.0.130
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_hooks:
          - 10.1.0.130
          iocage_ip4: '-'
          iocage_ip4_dict:
            ip4: []
            msg: DHCP (running -- address requires root)
          iocage_ip6: '-'
          iocage_jid: '38'
          iocage_release: 13.4-RELEASE-p2
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail
        test_102:
          ansible_host: 10.1.0.245
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_hooks:
          - 10.1.0.245
          iocage_ip4: '-'
          iocage_ip4_dict:
            ip4: []
            msg: DHCP (running -- address requires root)
          iocage_ip6: '-'
          iocage_jid: '39'
          iocage_release: 13.4-RELEASE-p2
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail
        test_103:
          ansible_host: 10.1.0.180
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_hooks:
          - 10.1.0.180
          iocage_ip4: '-'
          iocage_ip4_dict:
            ip4: []
            msg: DHCP (running -- address requires root)
          iocage_ip6: '-'
          iocage_jid: '40'
          iocage_release: 13.4-RELEASE-p2
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request inventory inventory plugin plugins plugin (any type) labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request inventory inventory plugin plugins plugin (any type)
Projects
None yet
Development

No branches or pull requests

2 participants