gpt4 book ai didi

linux - Ansible 文件模块错误 - chown 失败 : failed to look up user

转载 作者:行者123 更新时间:2023-12-05 01:44:45 26 4
gpt4 key购买 nike

我正在尝试使用 file 模块更改文件的 owner。我试过这段代码:

---
- hosts: super_group
remote_user: ec2-user
tasks:
- name: Checking the user name
shell: /usr/bin/whoami
register: username

- name: Debugging the whoami username
debug: msg={{ username }}

- name: Changing the owner of a file
file: path=/home/ec2-user/test owner={{ username }}

错误:

TASK [Changing the owner of a file] ********************************************
fatal: [test]: FAILED! => {"changed": false, "failed": true, "gid": 0, "group": "root", "mode": "0644", "msg": "chown failed: failed to look up user {'stderr_lines': [], 'changed': True, 'end': '2017-07-10 01:49:11.495709', 'stdout': 'ec2-user', 'cmd': '/usr/bin/whoami', 'start': '2017-07-10 01:49:11.492286', 'delta': '0:00:00.003423', 'stderr': '', 'rc': 0, 'stdout_lines': ['ec2-user']}", "owner": "ec2-user", "path": "/home/ec2-user/test", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 0, "state": "file", "uid": 1000}
to retry, use: --limit @/home/ec2-user/ansible/test.retry

debug 模块给我这个输出:

TASK [Debugging the whoami username] *******************************************
ok: [test] => {
"msg": {
"changed": true,
"cmd": "/usr/bin/whoami",
"delta": "0:00:00.003423",
"end": "2017-07-10 01:49:11.495709",
"rc": 0,
"start": "2017-07-10 01:49:11.492286",
"stderr": "",
"stderr_lines": [],
"stdout": "ec2-user",
"stdout_lines": [
"ec2-user"
]
}
}

注意:

如果我对 username 的值进行硬编码,那么它可以正常工作:

  - name: Changing the owner of a file
file: path=/home/ec2-user/test owner=ec2-user

请让我知道如何解决这个问题。

最佳答案

没有问题。您要使用 username.stdout,而不是 username

请检查您使用调试模块打印的值并使用推理。

关于linux - Ansible 文件模块错误 - chown 失败 : failed to look up user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45004692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com