I am new to ansible, I am writing a small playbook where it has to collect the fact value from the destination host and use that as a variable within the play. Can someone help me how to do that.
---
- hosts: all
gather_facts: True
become: true
become_method: sudo
become_user: root
vars:
BUILD_PATH: /opt/services/dev
pre_tasks:
- setup:
filter: ansible_env
- set_fact:
tag: "{{ ansible_env.DATA_AGGREGATOR_ENV }}"
- debug: var=ENV
tasks:
- name: Copy to Build to DATA
shell: cp -pr {{ BUILD_PATH }} {{ ENV }}
Note: DATA_AGGREGATOR_ENV is environmental variable defined in all servers and the value vary from one server to other.
You set the variable
tag
, but you use the variableENV
.You have to set the
ENV
variable, if you want to use theENV
variable.Or you have to use the
tag
variable, if you have set thetag
variable.btw: the
filter
line lacks a space.