Ansible - Could not use lookup file module for a file under /etc/

丶灬走出姿态 提交于 2019-12-17 15:00:50

问题


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:

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

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.


回答1:


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

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 }}"


来源:https://stackoverflow.com/questions/47387155/ansible-could-not-use-lookup-file-module-for-a-file-under-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!