简体   繁体   English

为多个客户端使用 playbook 中的注册

[英]Using register in playbook for multiple clients

Hello Everyone.大家好。

First task in my playbook will be executed in server.我的剧本中的第一个任务将在服务器中执行。 Second task will be executed in clients.第二个任务将在客户端执行。 ## ##

First task : generate token numbers for all clients listed in inventory第一项任务:为清单中列出的所有客户生成令牌编号

- 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

Second task: Make clients to use generated token specific to them.第二个任务:让客户端使用生成的特定于他们的令牌。

(Example: ClientA should take ticket {{ hostvars['server']['ticket'][0]['stdout'] }} (例如:ClientA 应该取票 {{ hostvars['server']['ticket'][0]['stdout'] }}

output example for one client: "stdout": "9338e126e8dd454820870b3ba19f5344334c8b1d" ##一个客户端的输出示例:“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'] }}

Above plays works completely fine with one client but no idea to write play for multiple clients (in loop)以上播放对于一个客户端完全正常,但不知道为多个客户端编写播放(循环)

Need inputs to write shell value for below play (for multiple clients) ##需要输入来为下面的游戏写入 shell 值(对于多个客户端)##

 - hosts: "{{ clients }}" vars: clients: - clientA - ClientB tasks: shell: /path/to/bin --key /path/to/store-key/ticket.key --ticket !!!!!!!!Please your input here !!!!!!!!!

How can we achieve it?我们怎样才能实现它?

## ##

One of possible solutions is to可能的解决方案之一是

  1. Add to hosts in clients group index of the host在主机的clients组索引中添加到主机
clients:
  hosts:
    clientA:
      uid: 0
      <etc>
    clientB:
      uid: 1
      <etc>
  1. Add loop to server part (see below)将循环添加到服务器部分(见下文)
  2. Address the client's token by its uid as array index in ticket variable通过uid作为ticket变量中的数组索引来寻址客户端的令牌
- 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'] }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM