Skip to content

Rulebooks don't pass group_vars in inventory dirs, and don't support multiple inventories #817

@dhoffend

Description

@dhoffend

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that ansible-rulebook is open source software provided for free and that I might not receive a timely response.

Bug Summary

When pointing the inventory to prod/hosts the group_vars/all, group_vars/groupname and host_vars/hostname content within the inventory dictionary are not passed to the runner.

in addition when inventories are split into multiple inventories only one inventory is passed to the runner.

in addition inventories defined in ansible.cfg (configured via full path as env variable) are ignored

Environment

ansible-core 2.15 (i know it's not the newst, but we're limited due to targeted hosts)
ansible-rulebook 1.1.7
debiab bookworm

Steps to reproduce

ansible.cfg

[defaults]
inventory = ./global/empty,./prod/hosts

global/empty

# dummy repo for global settings across multiple environments

global/group_vars/all/vars.yml

---
global_all_loaded: true

prod/hosts

[testhost]
localhost

prod/group_vars/all/vars.yml

---
prod_all_loaded: true

rulebook.yml

---
- name: Rulebook to print debug message based on webhook event
  hosts: testhost
  gather_facts: false

  sources:
      - ansible.eda.webhook:
          host: 127.0.0.1
          port: 6000
  rules:
      - name: Launch playbook on start command
        condition: event.payload.command == 'start'
        action:
           run_playbook:
               name: playbook.yml

playbook.yml

---
- name: Demo Playbook
  hosts: testhost
  gather_facts: false
  connection: local
  tasks:
    - name: Print hostvars
      ansible.builtin.debug:
        msg: "{{ hostvars[inventory_hostname] }}"

Actual results

  • group_vars in inventory directories are ignored
  • multiple inventories are ignored

Expected results

  • All inventories similar to ansible-playbook command are loaded and respected
  • Multiple inventories (used for centralized settings across multiple inventories/environments are respected)
  • group and host vars are correctly loaded and passed to the runner etc
  • inventories contents are indentical when executed a nd compared rulebook to playbook
  • I havent tested dynamic inventories yet (they should be loaded on runtime)

Additional information

Playbook execution (example)

ANSIBLE_CONFIG=/opt/rulebook/test/ansible.cfg ansible-playbook playbook.yml

TASK [Print hostvars] **********************************************************
[...]
        "ansible_inventory_sources": [
            "/opt/rulebook/test/global/empty",
            "/opt/rulebook/test/prod/hosts"
        ],
[..]
        "global_all_loaded": true,
[..]
        "prod_all_loaded": true,
[..]

Rulebook Execution with Inventory in ansible.cfg

ANSIBLE_CONFIG=/opt/rulebook/test/ansible.cfg /opt/ansible/bin/ansible-rulebook --rulebook rulebook.yml

2025-07-01 13:46:29,126 - ansible_rulebook.cli - ERROR - Terminating: Rule Launch playbook on start command has an action run_playbook which needs inventory to be defined

Rulebook execution with multiple inventories via commandline + Curl Trigger

ANSIBLE_CONFIG=/opt/rulebook/test/ansible.cfg /opt/ansible/bin/ansible-rulebook --rulebook rulebook.yml -i global/empty -i prod/hosts -v

curl --location --request POST 'http://localhost:6000' --header 'Content-type: application/json' --data-raw '{"command":"start"}'

TASK [Print hostvars] **********************************************************
[...]
        "ansible_inventory_sources": [
            "/tmp/edarbh41_yv/inventory/hosts"
        ],
[...]
# prod_all_loaded and global_all_loaded are mittings

For the moment it looks like I can't use our existing inventory structures or just use ansible-rulebookt to execute ansible-playbook commands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions