include_vars not working correctly in case of remote hosts

Hello All,

I am trying to setup ansible script which fetches config file from S3 and stores on remote node in home directory for User. In next task I would like to include_vars from this file but somehow include_vars fails to find file on remote machine as it always looks in
my local machine.

  • hosts: XYZcompute.amazonaws.com
    connection: ssh
    remote_user: ubuntu
    gather_facts: False
    vars:
    remote_env:

    roles:

  • python

  • uwsgi
    tasks:

  • shell: echo $HOME
    register: USER_HOME
    ignore_errors: True

  • name: Access file from s3

s3: bucket=MYBUCKET object={{CONFIGURATION_ENV}}.yml dest=~/{{CONFIGURATION_ENV}}.yml mode=get force=true
environment: remote_env

  • name: “Loading vars”

include_vars: ‘~/{{CONFIGURATION_ENV}}.yml’
delegate_to: XYZ.compute.amazonaws.com

lets say I am invoking above playbook from user vikram include_vars fails saying

file could not read: /home/vikram/production.yml

but I want ansible to load variables from /home/ubuntu/production.yml

-Vikram

The end-goal is to get the variables loaded into your ansible run. How about separating out your task into two distinct activities:

  1. Fetching the file from S3 on the machine where you are doing the ansible run, and loading variables from it
  2. Uploading a copy of the file to the remote host’s home directory as well (if that is part of your requirements)
    Just my two cents.

include_vars always runs on your local machine, this is what it does :slight_smile: