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 inventory plugin iocage #9261

Open
1 task done
vbotka opened this issue Dec 16, 2024 · 4 comments
Open
1 task done

Add inventory plugin iocage #9261

vbotka opened this issue Dec 16, 2024 · 4 comments
Labels
feature This issue/PR relates to a feature request has_pr plugins plugin (any type)

Comments

@vbotka
Copy link
Contributor

vbotka commented Dec 16, 2024

Summary

FreeBSD iocage Jail manager provides lists of jails. Use it to create dynamic inventory.

Issue Type

Feature Idea

Component Name

New inventory plugin iocage

Additional Information

Example of the jail list

shell> ssh [email protected] iocage list
+------+----------+-------+--------------+------------+
| JID  |   NAME   | STATE |   RELEASE    |    IP4     |
+======+==========+=======+==============+============+
| None | test_101 | down  | 13.4-RELEASE | 10.1.0.101 |
+------+----------+-------+--------------+------------+
| None | test_102 | down  | 13.4-RELEASE | 10.1.0.102 |
+------+----------+-------+--------------+------------+
| None | test_103 | down  | 13.4-RELEASE | 10.1.0.103 |
+------+----------+-------+--------------+------------+

Example of the inventory configuration file

shell> cat iocage.yml
plugin: community.general.iocage
host: 10.1.0.18
user: admin
groups:
    test: inventory_hostname.startswith('test')

The playbook

 shell> cat pb-test.yml
- hosts: test

  tasks:

    - debug:
        msg: |
          inventory_hostname: {{ inventory_hostname }}
          {% for var in q('varnames', 'iocage_*') %}
          {{ var }}: {{ lookup('vars', var) }}
          {% endfor %}

    - debug:
        var: groups
      run_once: true

gives

shell> ansible-playbook pb-test.yml -i iocage.yml 

PLAY [test] ****************************************************************************************

TASK [debug] ****************************************************************************************
ok: [test_101] => 
  msg: |-
    inventory_hostname: test_101
    iocage_jid: -
    iocage_boot: off
    iocage_state: down
    iocage_type: jail
    iocage_release: 13.4-RELEASE-p2
    iocage_ip4: 10.1.0.101
    iocage_ip6: -
    iocage_template: ansible_client
    iocage_basejail: yes
ok: [test_102] => 
  msg: |-
    inventory_hostname: test_102
    iocage_jid: -
    iocage_boot: off
    iocage_state: down
    iocage_type: jail
    iocage_release: 13.4-RELEASE-p2
    iocage_ip4: 10.1.0.102
    iocage_ip6: -
    iocage_template: ansible_client
    iocage_basejail: yes
ok: [test_103] => 
  msg: |-
    inventory_hostname: test_103
    iocage_jid: -
    iocage_boot: off
    iocage_state: down
    iocage_type: jail
    iocage_release: 13.4-RELEASE-p2
    iocage_ip4: 10.1.0.103
    iocage_ip6: -
    iocage_template: ansible_client
    iocage_basejail: yes

TASK [debug] ****************************************************************************************
ok: [test_101] => 
  groups:
    all:
    - test_101
    - test_102
    - test_103
    test:
    - test_101
    - test_102
    - test_103
    ungrouped: []

PLAY RECAP ****************************************************************************************
test_101                   : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
test_102                   : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
test_103                   : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
vbotka added a commit to vbotka/community.general that referenced this issue Dec 16, 2024
@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
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module plugins plugin (any type) labels Dec 16, 2024
@ansibullbot
Copy link
Collaborator

Files identified in the description:

  • lib/ansible/plugins/inventory

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 removed the module module label Dec 16, 2024
@dch
Copy link

dch commented Dec 16, 2024

@vbotka nice! how can I help with review process here?

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 has_pr plugins plugin (any type)
Projects
None yet
Development

No branches or pull requests

3 participants