【问题标题】:Ansible: Unable to create /etc/ansible/facts.d/openshift.fact, permission deniedAnsible:无法创建 /etc/ansible/facts.d/openshift.fact,权限被拒绝
【发布时间】:2015-12-02 22:34:30
【问题描述】:

我正在关注this blog 使用 ansible 在 OpenStack 上安装 OpenShift Origin V3。但我收到错误

"无法创建事实文件:%s,错误:%s" % (filename, ex) ma​​in.OpenShiftFactsFileWriteError:无法创建事实文件:/etc/ansible/facts.d/openshift.fact,错误:[Errno 13] 权限 拒绝:'/etc/ansible/facts.d'

目标系统是 CentOS,我可以在目标系统上执行无密码 sudo。我什至加了/etc/sudoers

centos All=(ALL) NOPASSWD:ALL

到所有节点以及我正在运行 ansible 的系统上。

在我运行 ansible 的系统中,我尝试以 sudo 和 root 身份执行,但结果相同。

我不确定它在哪里面临权限被拒绝,我的意思是在主机或目标系统上。

Ansible 主机:

[OSEv3:children"]
masters
nodes

[OSEv3:vars]
ansible_ssh_user=centos
ansible_sudo=true
#ansible_ssh_user=root

product_type=openshift
deployment_type=origin

[masters]
192.168.144.132 openshift_public_hostname=master.novalocal openshift_ip=10.0.1.163 openshift_public_ip=192.168.144.132

[nodes]
192.168.144.128 openshift_public_hostname=node1.novalocal openshift_ip=10.0.1.164 openshift_public_ip=192.168.144.128 openshift_node_labels="{'region': 'primary', 'zone': 'east'}" 
192.168.144.129 openshift_public_hostname=node2.novalocal openshift_ip=10.0.1.165 openshift_public_ip=192.168.144.129 openshift_node_labels="{'region': 'primary', 'zone': 'west'}"

Ansible.cfg

[defaults]
hostfile = ansible_hosts
remote_user = centos
host_key_checking = False

以下是日志:

TASK: [openshift_facts | Ensure PyYaml is installed] ************************** 
ok: [192.168.144.132] => (item=PyYAML)

TASK: [openshift_facts | Gather Cluster facts] ******************************** 
failed: [192.168.144.132] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 6355, in <module>
    main()
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 1222, in main
    openshift_facts = OpenShiftFacts(role, fact_file, local_facts, additive_facts_to_overwrite)
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 999, in __init__
    self.facts = self.generate_facts(local_facts, additive_facts_to_overwrite)
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 1013, in generate_facts
    local_facts = self.init_local_facts(local_facts, additive_facts_to_overwrite)
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 1194, in init_local_facts
    save_local_facts(self.filename, new_local_facts)
  File "/home/centos/.ansible/tmp/ansible-tmp-1449035570.03-273189812167365/openshift_facts", line 924, in save_local_facts
    "Could not create fact file: %s, error: %s" % (filename, ex)
__main__.OpenShiftFactsFileWriteError: Could not create fact file: /etc/ansible/facts.d/openshift.fact, error: [Errno 13] Permission denied: '/etc/ansible'
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
Shared connection to 192.168.144.132 closed.


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/config.retry

192.168.144.132            : ok=6    changed=0    unreachable=0    failed=1   
localhost                  : ok=7    changed=0    unreachable=0    failed=0   

我之前没有使用 ansible 的经验,因此无法进行更多调试。

【问题讨论】:

  • 该错误表明 openshift_facts 模块无法写入远程主机上的 /etc/ansible/facts.d 目录。通常,我只在没有 sudo 的情况下以非 root 用户身份运行时看到此错误,但从您提供的清单 sn-ps 来看,这里似乎并非如此。如果您以 centos 用户手动 ssh 到 192.168.144.132 并尝试运行以下命令:sudo touch /etc/ansible/facts.d/openshift.fact。如果失败了,那么在继续之前需要解决导致 root 无法写入 /etc/ansible/facts.d 的任何问题。
  • @detiber sudo touch /etc/ansible/facts.d/openshift.fact 给出 No such file or directory 错误,可能是因为 fact.d 文件夹不存在。但我可以在/etc/ansible 文件夹中创建一个随机文件。
  • 你用的是什么版本的ansible?
  • 我不太确定是什么原因导致无法创建 fact.d 目录,因为如果目录(和父目录)不存在,我们会使用 os.makedirs 创建:@ 987654322@
  • @detiber 我无法访问我正在使用的机器,但我昨天从 yum 存储库安装了它,还从 github 克隆了 ansible。因此,它是 repo 和 github 中的最新版本。

标签: ansible ansible-playbook openshift-origin ansible-facts ansible-inventory


【解决方案1】:

解决方案似乎很简单。我在 google 的 ansible 组上找到了它。

只需要添加

sudo = true 
sudo_user = root

在 ansible.cfg 文件中。

至少这个错误消失了,但我遇到了新的错误。

编辑 正如下面 cmets 中所建议的,sudo_user 必须是 root,因此,相应地更改了分析器。

【讨论】:

  • 设置 sudo_user 似乎不正确,应该是 ansible 充当的用户,在这种情况下 应该 是 root 的默认值。
  • 你的意思是不应该添加它,默认情况下它需要 true & root 值?
  • sudo = true 应该不是真的需要,因为您的库存在 OSEv3 组上设置 ansible_sudo,但将它放在 ansible.cfg 文件中并没有任何害处。
  • sudo_user = centos 在执行任务时告诉 ansible sudo to centos 用户,该用户没有安装包或修改期间所需的许多文件的适当权限配置步骤。
猜你喜欢
  • 1970-01-01
  • 2015-06-18
  • 2016-02-12
  • 1970-01-01
  • 2018-05-10
  • 2015-12-25
  • 2019-12-16
  • 2017-09-07
  • 1970-01-01
相关资源
最近更新 更多