Re: [ansible-project] register variable can't be used in shell module?

2021-01-20 Thread liyo...@126.com
it works,thanks very mush 在2021年1月20日星期三 UTC+8 下午4:21:04 写道: > thanks,I try it : > shell: kubeadm join --control-plane {{ groups['master'][0] }}:6443 --token > {{ hostvars[groups['master']|first]['kubeadm_token'].stdout }} > --discovery-token-ca-cert-hash sha256:{{ > hostvars[groups['master']

Re: [ansible-project] register variable can't be used in shell module?

2021-01-20 Thread liyo...@126.com
thanks,I try it : shell: kubeadm join --control-plane {{ groups['master'][0] }}:6443 --token {{ hostvars[groups['master']|first]['kubeadm_token'].stdout }} --discovery-token-ca-cert-hash sha256:{{ hostvars[groups['master']|first]['kubeadm_hash'].stdout }} but the ansible-playbook command is sei

Re: [ansible-project] register variable can't be used in shell module?

2021-01-20 Thread Jean-Yves LENHOF
You could try something hostvars[groups['master']|first] instead of hostvars['master'] in my proposition to see it that works...not sure Use a debug module could help Regards, JYL Le 20/01/2021 à 08:53, liyo...@126.com a écrit : yes,I want only get one host in member of group ‘master’,how 

Re: [ansible-project] register variable can't be used in shell module?

2021-01-20 Thread liyo...@126.com
I just try to use set_fact,but only one one host: 47.108.234.26 get the token value,the other master node : 47.108.213.148 dont get it --- - hosts: master gather_facts: no tasks: - name: register hash shell: "openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -pubkey | openssl r

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread liyo...@126.com
yes,I want only get one host in member of group ‘master’,how to write it ? [root@localhost ~]# cat /etc/ansible/hosts [master] 47.108.222.84 47.108.234.26 47.108.213.148 only use "47.108.222.84" to do shell command 在2021年1月20日星期三 UTC+8 下午3:47:31 写道: > I'm wrong it's not hostvars['master'],

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread Jean-Yves LENHOF
I'm wrong it's not hostvars['master'], because master is not the name of your first host in group master Le 20/01/2021 à 08:33, Jean-Yves LENHOF a écrit : You're looking for something like this I think (not tested) :     - name: add master node       shell: "kubeadm join {{ groups['master

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread Jean-Yves LENHOF
You're looking for something like this I think (not tested)  :     - name: add master node       shell: "kubeadm join {{ groups['master']|first }}:6443 --token {{hostvars['master']['kubeadm_token'].stdout}} --discovery-token-ca-cert-hash sha256:{{hostvars['master']['kubeadm_hash'].stdout}} --c

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread Dick Visser
You could register the variable to a dummy host. It's a bit of a hack imho but it does work. https://stackoverflow.com/questions/33896847/how-do-i-set-register-a-variable-to-persist-between-plays-in-ansible On Wed, 20 Jan 2021 at 08:17, liyo...@126.com wrote: > I know,but I want get the token

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread liyo...@126.com
I know,but I want get the token in A host,use it in other hosts,how to do it ? 在2021年1月20日星期三 UTC+8 下午2:31:36 写道: > Hii > > You're registering a variable for one host (47.108.222.84) but then try to > use it for another (47.108.213.148). > > I'm have no experience with kubeadm but I think your

Re: [ansible-project] register variable can't be used in shell module?

2021-01-19 Thread Dick Visser
Hii You're registering a variable for one host (47.108.222.84) but then try to use it for another (47.108.213.148). I'm have no experience with kubeadm but I think your logic wrt host selection should be improved, so that you can reliably pick the variable from a stable group name, instead of "th

[ansible-project] register variable can't be used in shell module?

2021-01-19 Thread liyo...@126.com
when I edit a playbook test.yml: --- - hosts: master gather_facts: no tasks: - name: register 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' ' -f 2" register