【发布时间】:2019-11-05 11:04:03
【问题描述】:
我正在运行一个简单的剧本来测试设置 K8s,第一步是关闭交换,这需要提升才能成功。我在一个 ubuntu docker 容器上安装了 ansible,试图在另一个 centos 容器上运行该游戏,都在我的本地 Windows 机器上。
我的剧本
---
- hosts: local
become: yes
become_method: sudo
roles:
- kubernetes
失败的任务
---
- name: turn off swap
shell: |
swapoff -a
将结果输出剪切到相关部分
ok: [centosbox]
<172.66.2.66> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=config -o ConnectTimeout=10 -o ControlPath=/home/config/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.66.2.66 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-hvrarwhvnbwtveklbinfwigmrapurugb; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/config/.ansible/tmp/ansible-tmp-1572951151.19-42546213906525/command; rm -rf "/home/config/.ansible/tmp/ansible-tmp-1572951151.19-42546213906525/" > /dev/null 2>&1'"'"'"'"'"'"'"'"''"'"''
fatal: [centosbox]: FAILED! => {"changed": true, "cmd": "swapoff -a", "delta": "0:00:00.119504", "end": "2019-11-05 10:52:31.431316", "failed": true, "invocation": {"module_args": {"_raw_params": "swapoff -a",
"_uses_shell": true, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2019-11-05 10:52:31.311812", "stderr": "swapoff: Not superuser.", "stdout": "", "stdout_lines": [], "warnings": []}
输出 swapoff: Not superuser. 正是您期望以非提升用户身份运行命令的结果。用户在目标机器上设置为无密码 sudo,并且与运行 playbook 的用户相同。
[local]
centosbox ansible_host=172.66.2.66 ansible_user=config
我尝试改变设置,在不同级别添加变得,都导致同样的错误。我还尝试使用剧本中的不同方法运行 swapoff 命令,结果相同。 任何建议都非常感谢。
【问题讨论】:
-
可以加become_user:
-
我试过了,它返回了同样的错误
标签: ansible