Hi,

1/

Sounds like you use a lot the when clause to limit the impact of action to some servers.

Why you did'nt use more the hosts clause to handle the action on specific hosts ?

You can have more than one hosts clause in a playbook

Notice that you can reuse variable in a previous play in another play also.


2/

What do you want to achieve really ?


3/

Sounds weird to have three master and only one worker in a kubernetes cluster... The other way around is more "common"

Regards,

JYL


Le 21/01/2021 à 07:18, liyo...@126.com a écrit :
my inventroy file is below:
[master]
172.24.64.44
172.24.64.42
172.24.64.43
[worker]
172.24.64.46

[cluster:children]
master
worker

I want to exec the playbook in [cluster:children]'s master 172.24.64.44,want to get the variables value ,then use it in other group ,how to write the "when" ? please help me ?


my playbook is :
- name: Get master token
  shell: kubeadm token list |grep forever|awk '{print $1}'
  register: kubeadm_token
  when: inventory_hostname == groups['cluster:children']['master']|first

- name: Get master hash
  shell: "openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin 
-outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^ .* //'|cut -d' ' -f2"
  register: kubeadm_hash
when: xxxxxxxxxxxxxxxxxxxxxx

- name: Add master node
  shell:
    cmd: kubeadm join  {{ groups['master'][0] }}:6443 --token {{ 
hostvars[groups['cluster']['master']|first]['kubeadm_token'].stdout }}  
--discovery-token-ca-cert-hash sha256:{{ 
hostvars[groups['master']|first]['kubeadm_hash'].stdout }}
  when:
    - inventory_hostname in groups['worker']


I want to get the token and hash value,then use it in "worker" groups

--
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 ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7797386d-3d83-4a94-98e0-be9ccc47c69dn%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/7797386d-3d83-4a94-98e0-be9ccc47c69dn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a57b1200-4159-a2fa-984a-984df415114f%40lenhof.eu.org.

Reply via email to