Ansible - Could not use lookup file module for a f

2020-01-29 20:59发布

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条回答
男人必须洒脱
2楼-- · 2020-01-29 21:24

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 }}"
查看更多
登录 后发表回答