本文介绍了无法对/etc/下的文件使用查找文件模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署一台 CentOS 机器,其中一项任务是读取呈现给 Consul 服务的文件,该文件将其放置在 /etc/sysconfig 下.我稍后尝试使用 lookup 模块在变量中读取它,但它在下面引发错误:

I am deploying a CentOS machine and one among the tasks was to read a file that is rendered the Consul service which places it under /etc/sysconfig. I am trying to later read it in a variable using the lookup module but it is throwing an error below:

致命:[ansible_vm1]:失败!=> {"failed": true, "msg": "在查找中找不到文件:/etc/sysconfig/idb_EndPoint"}

但我在生成 idb_EndPoint 文件的点下方运行查找任务方式,并且我手动登录以验证文件可用.

But I am running the lookup task way below the point where the idb_EndPoint file is generated and also I looked it up manually logging in to verify the file was available.

 - name: importing the file contents to variable
   set_fact:
     idb_endpoint: "{{ lookup('file', '/etc/sysconfig/idb_EndPoint') }}"
   become: true

我还尝试使用另一个用户 become_user: deployuserbecome: true 进行权限升级,但仍然无法正常工作.使用 Ansible 版本 2.2.1.0.

I also tried previlege escalations with another user become_user: deployuser along with become: true but didn't work still. Using the Ansible version 2.2.1.0.

推荐答案

Ansible 中的所有查找插件都在中控机本地执行.

All lookup plugins in Ansible are executed locally on the control machine.

改为使用 slurp 模块:

Instead use slurp module:

- name: importing the file contents to variable
  slurp:
    src: /etc/sysconfig/idb_EndPoint
  register: idb_endpoint_b64
  become: true

- set_fact:
    idb_endpoint: "{{ idb_endpoint_b64.content | b64decode }}"

这篇关于无法对/etc/下的文件使用查找文件模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:56