我正在运行一个简单的剧本来测试设置K8,第一步是关闭交换,这需要提升才能成功。我在一个ubuntu docker容器上安装了ansible,试图在本机Windows机器上的另一个centos容器上运行该播放。
我的剧本
---
- 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:不是超级用户。正是您期望以非提升用户身份运行命令的结果。在目标计算机上将用户设置为无密码sudo,并且该用户正在运行剧本。
[local]
centosbox ansible_host=172.66.2.66 ansible_user=config
我尝试过更改设置,添加级别不同,所有这些都会导致相同的错误。我还尝试使用剧本中的不同方法运行swapoff命令,结果相同。 任何建议,不胜感激。