ansible-rulebook
ansible-rulebook copied to clipboard
Leverage inventory plugins for actions
- ansible-rulebook version:
0.10.1
- Python version:
3.11.0
- Operating System:
fedora:37
Description
I am trying to leverage the aws inventory plugin for an action. I would like my action to run against ec2 instances deployed in aws. The aws inventory plugin allows me to dynamically look up the instances I want to run against using the aws API.
I would also like to leverage the aws ssm connection plugin.
What I Did
I am running ansible-rulebook pointed to my aws inventory. This is the same inventory I want my action to use.
ansible-rulebook --rulebook rulebook.yml -i inventory/aws_ec2.yml --verbose
My rulebook...
---
- name: Listen for events on a webhook
hosts: all
sources:
- ansible.eda.webhook:
host: 0.0.0.0
port: 5000
rules:
- name: Prepare build server
condition: event.payload.message == "Prep Build Server"
action:
run_playbook:
name: tasks/build_server.yml
The file tasks/build_server.yml
- hosts: build_server
vars:
ansible_connection: aws_ssm
ansible_aws_ssm_bucket_name: ansible-eda-demo
ansible_aws_ssm_region: us-east-1
tasks:
- name: Install all packages for bender
dnf:
name:
- python3-pip
- buildah
- podman
- ansible
- docker
- name: Start dockerd
systemd:
name: docker
state: started
- name: install bender
pip:
name:
- ansible-bender
My inventory leveraging the aws inventory plugin
plugin: aws_ec2
regions:
- us-east-1
filters:
instance-state-name: running
compose:
ansible_host: instance_id
keyed_groups:
- key: tags.Name
separator: ''
Here is the output when ansible-rulebook attempts to run the action build_server
.
2/3/2023, 2:16:41 PM | PLAY RECAP *************** | eda-demo
2/3/2023, 2:16:41 PM | skipping: no hosts matched | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: * Failed to parse /tmp/run_playbookmfk3b58g/inventory/hosts with | eda-demo
2/3/2023, 2:16:41 PM | yaml plugin: Plugin configuration YAML file, not YAML inventory | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: * Failed to parse /tmp/run_playbookmfk3b58g/inventory/hosts with | eda-demo
2/3/2023, 2:16:41 PM | ini plugin: Invalid host pattern 'compose:' supplied, ending in ':' is not | eda-demo
2/3/2023, 2:16:41 PM | allowed, this character is reserved to provide a port. | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: Unable to parse /tmp/run_playbookmfk3b58g/inventory/hosts as an | eda-demo
2/3/2023, 2:16:41 PM | inventory source | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: Unable to parse /tmp/run_playbookmfk3b58g/inventory as an inventory | eda-demo
2/3/2023, 2:16:41 PM | source | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: No inventory was parsed, only implicit localhost is available | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: provided hosts list is empty, only localhost is available. Note that | eda-demo
2/3/2023, 2:16:41 PM | the implicit localhost does not match 'all' | eda-demo
2/3/2023, 2:16:41 PM | [WARNING]: Could not match supplied host pattern, ignoring: build_server | eda-demo
From the output, it appears the action run is looking for a default host file and not the inventory that ansible-rulebook was passed. What inventory do the actions use? Is it possible to get an action to use a custom inventory?
Hello @quietjoy Ansible-rulebook doesn't process inventories through ansible plugins. Currently only static inventories in yaml format are supported. We have plan to extend the support in the future.