Ansible-无法在/etc/下的文件使用查找文件模块 [英] Ansible - Could not use lookup file module for a file under /etc/

查看:178
本文介绍了Ansible-无法在/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]:失败! => {失败":true,"msg":无法在查找中找到文件:/etc/sysconfig/idb_EndPoint"}

fatal: [ansible_vm1]: FAILED! => {"failed": true, "msg": "could not locate file in lookup: /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 }}"

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆