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

Task 'Disable swap' fails when there is no swap configured on a node #6642

Closed
neuliuyin opened this issue Sep 9, 2020 · 8 comments · Fixed by #6703 or #10077
Closed

Task 'Disable swap' fails when there is no swap configured on a node #6642

neuliuyin opened this issue Sep 9, 2020 · 8 comments · Fixed by #6703 or #10077
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@neuliuyin
Copy link

Environment:

  • OS (printf "$(uname -srm)\n$(cat /etc/os-release)\n"):
    Linux 3.10.0-1127.el7.x86_64 x86_64
    NAME="CentOS Linux"
    VERSION="7 (Core)"

  • Version of Ansible (ansible --version):
    ansible 2.9.6

  • Version of Python (python --version):
    python version = 3.7.3 (default, Aug 4 2020, 19:30:55) [Clang 11.0.3 (clang-1103.0.32.62)]

  • Kubespray version (commit) (git rev-parse --short HEAD):
    kubespray-2.13.3

  • Command used to invoke ansible:
    ansible-playbook -i contrib/inventory_builder/k8s_hosts.yaml cluster.yml --user centos -b --check

  • Output of ansible run:
    fatal: [master1]: FAILED! => {"msg": "The conditional check 'swapon.stdout' failed. The error was: error while evaluating conditional (swapon.stdout): 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/Users/lyin/Downloads/kubespray-2.13.3/roles/kubernetes/preinstall/tasks/0010-swapoff.yml': line 16, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n changed_when: no\n- name: Disable swap\n ^ here\n"}

  • Anything else do we need to know:

    [root@master1 ~]# free
                  total        used        free      shared  buff/cache   available
    Mem:        1881860      108348     1553428       16884      220084     1612312
    Swap:             0           0           0
    [root@master1 ~]# swapon -s
    [root@master1 ~]#
@neuliuyin neuliuyin added the kind/bug Categorizes issue or PR as related to a bug. label Sep 9, 2020
@floryut
Copy link
Member

floryut commented Sep 9, 2020

@neuliuyin could you put the entire log ? and if possible add (between line 15 and 16)

        - debug:
                msg: "{{ swapon }}"

I'm trying to reproduce but can't seem to be able to have a commands without stdout attribute.

@neuliuyin
Copy link
Author

@floryut here is debug output:

TASK [debug] ***********************************************************************************************************************************
ok: [master1] => {
    "msg": {
        "changed": false,
        "cmd": [
            "/sbin/swapon",
            "-s"
        ],
        "delta": "0:00:00.004486",
        "end": "2020-09-10 06:45:08.465100",
        "failed": false,
        "rc": 0,
        "start": "2020-09-10 06:45:08.460614",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "",
        "stdout_lines": []
    }
}

@floryut
Copy link
Member

floryut commented Sep 10, 2020

Wahou... That's what I got..I really don't understand how the ansible task report the swapon as missing an stdout parameter as you clearly got one.

@neuliuyin
Copy link
Author

neuliuyin commented Sep 10, 2020

Maybe check whether swapon.stdout is null or its length.

@EppO
Copy link
Contributor

EppO commented Sep 11, 2020

Maybe check whether swapon.stdout is null or its length.

shouldn't need it, the code is quite simple:

- name: check swap
  command: /sbin/swapon -s
  register: swapon
  changed_when: no

this takes the output of /sbin/swapon -s into the variable swapon in the object you pasted with the debug msg task. And it always runs (no when: attribute), hence it should get populated no matter what, with the stdout attribute.

- name: Disable swap
  command: /sbin/swapoff -a
  when: swapon.stdout

It's using the swapon object and extracts the stdout attribute from it. It works with your msg debug task but not that one, it's really weird. Are you sure you run your first cluster.yaml command with -b ? swapon is in /sbin, accessible only by root user. But it would fail at the swapon task I assume...

@neuliuyin-new
Copy link

@EppO I'm sure -b was there when the issue happened.

I checked again and found that the issue is caused by the --check flag.
When running in this mode, task check swap is somehow skipped and causes the exception in task Disable swap.

image

@floryut
Copy link
Member

floryut commented Sep 17, 2020

Interesting, will check that and maybe put a check_mode: no on the check swap as it's only a task for getting some value, it won't do any harm.

@floryut
Copy link
Member

floryut commented Sep 17, 2020

I've submit a PR, WDYT ?

VannTen added a commit to VannTen/kubespray that referenced this issue Nov 3, 2023
We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).
VannTen added a commit to VannTen/kubespray that referenced this issue Nov 3, 2023
We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).
VannTen added a commit to VannTen/kubespray that referenced this issue Nov 3, 2023
We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).
VannTen added a commit to VannTen/kubespray that referenced this issue Nov 18, 2023
We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).
VannTen added a commit to VannTen/kubespray that referenced this issue Nov 18, 2023
We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).
k8s-ci-robot pushed a commit that referenced this issue Dec 7, 2023
* Mask systemd swap.target do disable swap

This is a more generic way to disable swap, since it pulls .swap units
in systemd distributions; fstab is only one way to generate .swap units.

* Unconditionally disable swap

We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue #6642).

* Don't explicitly disable swapOnZram

We're already masking the swap.target, which would pull the zram unit,
hence no need to handle zram-generator specifically.
pedro-peter pushed a commit to pedro-peter/kubespray that referenced this issue May 8, 2024
* Mask systemd swap.target do disable swap

This is a more generic way to disable swap, since it pulls .swap units
in systemd distributions; fstab is only one way to generate .swap units.

* Unconditionally disable swap

We only care to disable it (the "swapon" registered variable is not used
anywhere else.
This allows to get rid of the ignore_errors, since this was added
because swapon.stdout does not exist in check_mode (see issue kubernetes-sigs#6642).

* Don't explicitly disable swapOnZram

We're already masking the swap.target, which would pull the zram unit,
hence no need to handle zram-generator specifically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
4 participants