0
votes

I have JSON file with contents

env_variables.json

{ "server": "{{server}}" , "notes": "{{notes}}" }

and ansible-playbook as below: (to upload a lambda with the environment variables)

playbook.yml

- hosts: localhost
  vars:
    server: localhost
    notes: hello this is localhost
  tasks:
    - name: Lambda creation/updation
      lambda:
        name: ansible_test
        state: present
        region: "eu-west-1"
        role: 'arn:aws:iam::xyz:role/xyz_lambda'
        zip_file: '{{ item.path }}'
        runtime: 'python3.6'
        environment_variables: "{{ lookup('file','/env_variables.json') | from_json }}"
        handler: 'lambda_function.lambda_handler'

How can I use the above-mentioned "env_variables.json" file format to insert the environment variables with values mentioned in the "vars" directive of playbook.yml?

1

1 Answers

1
votes

Use include_vars for that.

- name: Load data from json
  include_vars: file=/env_variables.json

If this file is outside of normal lookup pathes, you can use set_fact module:

- name: Load data from json
  set_fact:
    loaded_data: '{{ lookup('file','/env_variables.json') | from_json }}'