我有包含内容的JSON文件
env_variables.json
{ "server": "{{server}}" , "notes": "{{notes}}" }
和ansible-playbook如下:(用于上传带有环境变量的lambda)
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'
如何使用上述“ env_variables.json” 文件格式插入具有 “ vars” 中提到的值的环境变量 playbook.yml 的strong>指令?
答案 0 :(得分:0)
为此使用include_vars
。
- name: Load data from json
include_vars: file=/env_variables.json
如果此文件不在正常的查找路径中,则可以使用set_fact
模块:
- name: Load data from json
set_fact:
loaded_data: '{{ lookup('file','/env_variables.json') | from_json }}'