Hi,
We've run into an issue (and a pattern really) using ansible that we've
been unable to solve and I'm hoping the list can teach us the "ansible way".
The background is that we want to create a number of monitors
automatically, based on certain information. The solution we have today is
a variable:
monitor_exchanges:
- name: exchange1
demand_partners:
- 'dp1'
- 'dp2'
And the consumer:
- name: Create datadog monitors
datadog_monitor:
state: "present"
type: "query alert"
name: '{{item.0.name}}-{{item.1}} over delivery'
query:
"avg({{monitor_interval}}):100*(avg:requests.outbound.transmitted.count{sp_name:{{item.0.name}},
dp_name:{{item.1}}} - avg:demand_partner.rps{sp_name:{{item.0.name}},
dp_name:{{item.1}}})/avg:demand_partner.rps{sp_name:{{item.0.name}},
dp_name:{{item.1}}} > {{monitor_threshold}}"
message: "test"
api_key: "{{datadog_api_key}}"
app_key: "{{datadog_app_key}}"
with_subelements:
- monitor_exchanges
- demand_partners
when: monitor_exchanges is defined
This then creates, for each exchange a monitor per demand partner. That
part is fairly easy and works fine but we wanted to externalize the
'query'/'name'/'message' part of the above thing, so that we'd have
something more like:
- name: Create monitors
datadog_monitor:
state: "present"
type: "query alert"
query: {{item.something.query}}
name: {{item.something.query}}
message: {{item.something.query}}
We kept trying to do this with two datastructures, the one from above and
then
something like "monitors" that would be a list of hashes containing each
monitor to create. I couldn't come up with the right combination of
iteration to make it work however, because I really needed to iterate over
two separate things in different ways, I couldn't just list the two
structures, I needed to do something more like:
with_nested:
- with_subelements:
- monitor_exchanges
- demand_partners
- monitors
Is there another way I can model this that makes sense? I really just want
to iterate over a list of monitors and then for each monitor iterate over
the `monitor_exchanges` list to pull all the appropriate data.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5e2b9670-fa7c-44ee-bbf1-d8549165bf56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.