问题描述
我正在部署一台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:
但是我正在生成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: deployuser
和become: 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 }}"
这篇关于Ansible-无法在/etc/下的文件使用查找文件模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!