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

Add check that kube-master, kube-node and etcd groups are not empty. #3367

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions roles/kubernetes/preinstall/tasks/0020-verify-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
- ansible_version.full|version_compare('2.3.0', '>=')
run_once: yes

- name: Stop if either kube-master, kube-node or etcd is empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this create any issues when you run playbooks like upgrade / scale and you limit to either masters, nodes or etcd's ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I didn't think of it.
I'll check...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works like a charm. ansible is clever enough to keep groups and other settings intact while using --limit. If to thing carefully it should behave this way because while limiting to some hosts you may still need group and host vars from others. Or you may need to delegate a task to another host. So ansible can't touch your inventory.

2018-09-20 16:52:08 mgserjio: tmp$ cat i.ini
[kube-master]
master1 ansible_host=127.0.0.1

[etcd]
etcd1 ansible_host=127.0.0.1

[kube-node]
node1 ansible_host=127.0.0.1
node2 ansible_host=127.0.0.1
node3 ansible_host=127.0.0.1
node4 ansible_host=127.0.0.1
node5 ansible_host=127.0.0.1

[k8s-cluster:children]
kube-master
kube-node
2018-09-20 16:52:21 mgserjio: tmp$ cat task.yml
- hosts: k8s-cluster
  connection: local

  tasks:
    - name: Stop if either kube-master, kube-node, etcd is empty
      assert:
        that: groups.get('{{ item }}')
      with_items:
        - kube-master
        - kube-node
        - etcd

- hosts: kube-node
  connection: local

  tasks:
    - name: Stop if either kube-master, kube-node, etcd is empty
      assert:
        that: groups.get('{{ item }}')
      with_items:
        - kube-master
        - kube-node
        - etcd
2018-09-20 16:52:27 mgserjio: tmp$ ansible-playbook -i i.ini task.yml --limit master1

PLAY [k8s-cluster] **********************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [master1]

TASK [Stop if either kube-master, kube-node, etcd is empty] *****************************************************************************************************************************
ok: [master1] => (item=kube-master) => {
    "changed": false,
    "item": "kube-master",
    "msg": "All assertions passed"
}
ok: [master1] => (item=kube-node) => {
    "changed": false,
    "item": "kube-node",
    "msg": "All assertions passed"
}
ok: [master1] => (item=etcd) => {
    "changed": false,
    "item": "etcd",
    "msg": "All assertions passed"
}

PLAY [kube-node] ************************************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ******************************************************************************************************************************************************************************
master1                    : ok=2    changed=0    unreachable=0    failed=0

assert:
that: groups.get('{{ item }}')
with_items:
- kube-master
- kube-node
- etcd
run_once: true

- name: Stop if non systemd OS type
assert:
that: ansible_service_mgr == "systemd"
Expand Down