Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes master must be first host on the list #10

Closed
wiktorn opened this issue Aug 5, 2018 · 3 comments
Closed

Kubernetes master must be first host on the list #10

wiktorn opened this issue Aug 5, 2018 · 3 comments

Comments

@wiktorn
Copy link

wiktorn commented Aug 5, 2018

Because of this part of the code:

- name: Get the kubeadm join command from the Kubernetes master.
  shell: kubeadm token create --print-join-command
  changed_when: False
  when: kubernetes_role == 'master'
  run_once: True
  register: kubernetes_join_command

And the note in run_once docs:

Any conditional (i.e when:) will use the variables of the ‘first host’ to decide if the task runs or not, no other hosts will be tested.

Means that this recipe will work only, if the kubernetes master is the first host. If it's not the first one, then the when will evaluate to False and never will be run.

As my Ansible foo is quite low for now, I didn't found (yet) any fix for this

@wiktorn
Copy link
Author

wiktorn commented Aug 5, 2018

And I have the other issue connected with the above:

I have a site.yml playbook:

- import_playbook: k8s-master.yml
- import_playbook: k8s-nodes.yml

And k8s-master.yml looks like that:

- hosts: k8s-master
  vars:
    [...]
    kubernetes_role: "master"
  roles:
  - geerlingguy.pip
  - geerlingguy.docker
  - geerlingguy.kubernetes

And my k8s-nodes.yml looks as follows:

-   hosts: k8s-nodes
  vars:
    [...]
    kubernetes_role: "node"
  roles:
  - geerlingguy.docker
  - geerlingguy.kubernetes

In this configuration - kubectl join command will be gathered when running on k8s-master host group, and then again - when running on k8s-nodes host group, which will overwrite the command and the whole setup fails with:

fatal: [fc-node-01]: 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 have been in '/home/w/.ansible/roles/geerlingguy.kubernetes/tasks/node-setup.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Join node to Kubernetes master\n  ^ here\n"}

So I guess the root of the problem is the separation between two groups

@geerlingguy
Copy link
Owner

I think I might have a fix for this; basically instead of run_once, I need to have it only set a value if the role is master, and not overwrite the registered output. I'm trying a few different conditionals to see what works.

@geerlingguy
Copy link
Owner

Had to do a little more wrangling with facts and delegation to make sure the new join command is available to all servers... but I think I have a working solution. Testing in a local build now.

vulturm pushed a commit to vulturm/ansible-role-kubernetes that referenced this issue Mar 23, 2020
=============================================
This represents the squashed history as it is not too relevant for us..

Below are all the commit messages:
=============================================

Change a line to trigger a Travis CI build.

A few small fixes for automated test builds.

More updates to make things work better in various situations.

Fix idempotence for web ui enablement.

Fix dashboard UI service.

Fix kube utils installation not working on Debian.

Fix install on CentOS 7.

Fix idempotence for Flannel networking task.

Really fix idempotence for Flannel tasks, and get CentOS mostly working.

Add more variables and docs.

Space in the defaults file. [ci skip]

Issue geerlingguy#3: Allow failures on CentOS 7 Travis CI build for now.

Fixes geerlingguy#2: Make role work with nodes joining master.

Spellcheck.

Reload kubelet unit file if config is changed.

Fixes geerlingguy#3: CentOS builds now passing.

Change order when applying flannel templates.

Issue geerlingguy#5: Add more configuration ability to default Flannel network manifests.

Tick kubernetes stable version up from 1.10 to 1.11

Fixes geerlingguy#10: Set kubernetes_join_command more reliably.

Fixes geerlingguy#15: Add kubelet extra args to the correct file for 1.11 and beyond.

Fixes geerlingguy#16: CentOS 7 configuration of KUBELET_EXTRA_ARGS was broken.

Update master-setup.yml

Add option for additional kubeadm init options

Update main.yml

kubeadm_init_opts default value

Changes for the comments under PR geerlingguy#19

Switch tests to use Molecule.

Issue geerlingguy#17: Attempt to fix installation on CentOS.

Issue geerlingguy#18: Attempt to fix version pinning issues on RedHat and Debian.

Fix boolean on Debian setup, add more tests.

Fixing lint issues

incredibly sloppy day.

fix typo kuberenetes

PR geerlingguy#24 follow-up: Use verbosity instead of debug variable for debug info.

Update tests for optimum efficiency.

Fix YAML error in molecule config.

Fixes failing Ubuntu 18.04 test.

Fix some new ansible-lint issues.

Issue geerlingguy#33: Set default Kubernetes version to 1.13.1.

Bump Kubernetes RHEL package to 1.13.3.

Fix ansible-lint issue - ignore rule 306.

Update kubelet-setup.yml

geerlingguy#42

Use same options for all tests and default to Ansible IP correctly.

Remove unused tests.

Fixes geerlingguy#54: Update to Kubernetes 1.15.

Fixes geerlingguy#55: Support and test Debian 10 Buster.

Fix typo referenced in geerlingguy#49

Update main.yml

Create FUNDING.yml

YAML syntax fix.

Add kubernetes_join_command_extra_opts variable.

calico cni choice

PR geerlingguy#53 follow-up: Requested changes for simplicity.

PR geerlingguy#53 follow-up: Add test for calico networking.

PR geerlingguy#53 follow-up: Remove extra conditional.

Bump to Kubernetes 1.16.

Default to calico 3.10 manifest.

PR geerlingguy#53 follow-up: Remove extra unneccessary loop.

Fix README formatting.

Add a test for CentOS 8.

Update molecule configuration to work with 3.0.

Update molecule configuration to work with 3.0.

Update molecule configuration to work with 3.0.

Make sure molecule lint script has set -e option.

Add probot/stale configuration to repository for stale issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants