I am using a shell script and Ansible to stop services in a defined order. Ansible uses Jinja template and shell is used to get services and node in which it needs to be stopped
Let me explain my current setup. Shell line which calls the playbook $targetappname relates to services, $node relates to key/value in a playbook which contains the services in that node.
ansible-playbook -i inventories/<<systemname>>.ini --limit "$node" playbooks/stop-services.yml -t -u "$1" --ask-pass --ask-become-pass --extra-vars "mode=$mode target_app_name=$target_app_name"
;;
systemname.yml
[host1-n1]
host
[services in that:vars]
components=service1,service 2
[host2-n1]
host
[services in that:vars]
components=service1,service 2
[host1-n2]
host
[services in that:vars]
components=service1,service 2
[host2-n2]
host
[services in that:vars]
components=service1,service 2
[node1:children]
host1-n1
host2-n1
[node2:children]
host1-n2
host2-n2
services yml file
{"stopOrder":{"node1":['service1','service2'],"node2":['service1','service2']]}}
stop-services.yml
---
- name: somename
hosts: {{node}}
become: true
gather_facts: false
role: stop-services
vars:
- stop_apps: |
{% for list in services.stopOrder.{{node}} if mode=='all' -%}
........
.........
..........
.........
I want the last line of the above code to pick services.yml-> stoporder->node selected by user during shell execution.
I am not sure how a shell variable can be used to call a particular node which is inside services.yml.