First task in my playbook will be executed in server. Second task will be executed in clients. ##
- hosts: Server
vars:
clients:
- clientA
- ClientB
tasks:
- name: generate ticket on server and save it as a variable
shell: /path/to/bin ticket {{ clients }}
register: ticket
(Example: ClientA should take ticket {{ hostvars['server']['ticket'][0]['stdout'] }}
output example for one client: "stdout": "9338e126e8dd454820870b3ba19f5344334c8b1d" ##
Note: below play is for one client- hosts: ClientA tasks: shell: /path/to/bin --key /path/to/store-key/ticket.key --ticket {{ hostvars['server']['ticket']['stdout'] }}
Need inputs to write shell value for below play (for multiple clients) ##
- hosts: "{{ clients }}" vars: clients: - clientA - ClientB tasks: shell: /path/to/bin --key /path/to/store-key/ticket.key --ticket !!!!!!!!Please your input here !!!!!!!!!
##
One of possible solutions is to
clients
group index of the hostclients:
hosts:
clientA:
uid: 0
<etc>
clientB:
uid: 1
<etc>
uid
as array index in ticket
variable- hosts: serverA
tasks:
- name: generate ticket on server and save it as a variable
shell: /path/to/bin ticket {{ item }}
register: ticket
with_items:
- "{{ groups['clients'] }}"
- hosts: clients
tasks:
- name: checkticket
shell: /path/to/bin --key /path/to/store-key/ticket.key --ticket {{ hostvars['serverA']['ticket']['results'][uid]['stdout'] }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.