ansible/event-driven-ansible

Does rulebook allow it to play a specific role based playbook?

darthVikes opened this issue · 3 comments

For ansible-playbooks I have an ansible.cfg file that allows me to change the roles directory, Does ansible-rulebook allow me to do the same? Does the runner call ansible-playbook to where your playbook is?

ansible.cfg

[defaults]

additional paths to search for roles in, colon separated

roles_path = ./roles

ansible-rulebook -r rulebook.yaml -i inventory.yml --verbose

rulebook.yaml

  • name: Read messages from a kafka topic and act on them
    hosts: all

    Define our source for events

    sources:

    • ansible.eda.kafka:
      host: localhost
      port: 9092
      topic: eda-topic
      group_id:

    Define the conditions we are looking for

    rules:

    • name: Say Hello
      condition: event.message == "Ansible is cool"

      Define the action we should take should the condition be met

      action:
      run_playbook:
      name: expand-vm-disks.yaml

expand-vm-disks.yaml

  • hosts: localhost
    gather_facts: false
    vars:
    guest_os: "{{ lookup('env','guest_os') }}"
    roles:
    • expand-vm-disks

pwd
/ansible/rulebook.yaml
/ansible/inventory.yaml
/ansible/expand-vm-disks.yaml
/ansible/ansible.cfg
/ansible/roles/expand-vm-disks/tasks/main.yaml

ERROR:

2023-03-09 21:05:05,789 - ansible_rulebook.builtin - INFO - Calling Ansible runner
ERROR! the role 'expand-vm-disks' was not found in /tmp/run_playbooky5u9tb11/project/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/tmp/run_playbooky5u9tb11/project

The error appears to be in '/tmp/run_playbooky5u9tb11/project/expand-vm-disks.yaml': line 39, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

roles:
- expand-vm-disks
^ here

Hi @darthVikes Thanks for your feedback.
Ansible-rulebook uses ansible-runner to execute ansible-playbook within a custom and temporal directory where the playbook, the inventory or variables are passed. Currently there is no support for custom config files for ansible. You can create a feature request in ansible-rulebook project.

As a workaround I suggest use your custom config through the ANSIBLE_CONFIG environment variable or moving that config into the default expected paths, like ~/.ansible.cfg you can see more details in the ansible documentation.

Gotcha! thanks! Apprecate the quick response.

Question was answered.