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 "the last item".


On Wed, 20 Jan 2021 at 05:26, liyo...@126.com <liyon...@126.com> wrote:

> 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: kubeadm_hash
>       when: inventory_hostname == groups['master']|first
>
>     - name: display hash
>       debug: msg="{{kubeadm_hash.stdout}}"
>       when: inventory_hostname == groups['master']|first
>
>     - name: register token
>       shell: kubeadm token list |grep forever|awk '{print $1}'
>       register: kubeadm_token
>       when: inventory_hostname == groups['master']|first
>
>     - name: display token
>       debug: msg="{{kubeadm_token.stdout}}"
>       when: inventory_hostname == groups['master']|first
>
>     - name: add master node
>       shell: "kubeadm join {{ groups['master'][0] }}:6443 --token
> {{kubeadm_token.stdout}} --discovery-token-ca-cert-hash
> sha256:{{kubeadm_hash.stdout}}  --control-plane"
>       when: inventory_hostname != groups['master']|first
>
>
> the results is below:
> PLAY [master]
> ***************************************************************************************************************************************************************
>
> TASK [register hash]
> ********************************************************************************************************************************************************
> skipping: [47.108.234.26]
> skipping: [47.108.213.148]
> changed: [47.108.222.84]
>
> TASK [display hash]
> *********************************************************************************************************************************************************
> ok: [47.108.222.84] => {
>     "msg":
> "af040f8e06e320e264a79f62b677b3267f4b681d869408658bdd121fa568216c"
> }
> skipping: [47.108.213.148]
> skipping: [47.108.234.26]
>
> TASK [register token]
> *******************************************************************************************************************************************************
> skipping: [47.108.234.26]
> skipping: [47.108.213.148]
> changed: [47.108.222.84]
>
> TASK [display token]
> ********************************************************************************************************************************************************
> ok: [47.108.222.84] => {
>     "msg": "otnb1h.cvagwwe7tgdvzbtx"
> }
> skipping: [47.108.234.26]
> skipping: [47.108.213.148]
>
> TASK [add master node]
> ******************************************************************************************************************************************************
> skipping: [47.108.222.84]
> fatal: [47.108.234.26]: FAILED! => {"msg": "The task includes an option
> with an undefined variable. The error was: 'dict object' has no attribute
> 'stdout'\n\nThe error appears to be in '/root/test.yml': line 23, column 7,
> but may\nbe elsewhere in the file depending on the exact syntax
> problem.\n\nThe offending line appears to be:\n\n\n    - name: add master
> node\n      ^ here\n"}
> fatal: [47.108.213.148]: FAILED! => {"msg": "The task includes an option
> with an undefined variable. The error was: 'dict object' has no attribute
> 'stdout'\n\nThe error appears to be in '/root/test.yml': line 23, column 7,
> but may\nbe elsewhere in the file depending on the exact syntax
> problem.\n\nThe offending line appears to be:\n\n\n    - name: add master
> node\n      ^ here\n"}
>
> PLAY RECAP
> ******************************************************************************************************************************************************************
> 47.108.213.148             : ok=0    changed=0    unreachable=0
> failed=1    skipped=4    rescued=0    ignored=0
> 47.108.222.84              : ok=4    changed=2    unreachable=0
> failed=0    skipped=1    rescued=0    ignored=0
> 47.108.234.26              : ok=0    changed=0    unreachable=0
> failed=1    skipped=4    rescued=0    ignored=0
>
> how to use it ?
>
> --
> 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/21ca354e-a0ed-4d10-9d01-8f48f170d22cn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/21ca354e-a0ed-4d10-9d01-8f48f170d22cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
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/CAL8fbwPwyFbMFO4uTTkknGs59KCPCL3C9OQxoz6CHiH5Y9SLbA%40mail.gmail.com.

Reply via email to