我的要求是我想在Ansible脚本中动态包含一个变量文件。我可以通过在我的安全任务中加入以下内容来做到这一点 -
- name: Include vars file
include_vars: vars/dev.yml
- name: Some other task
cp: copy something
如果我将dev.yml
保留在我的vars目录中,则上述工作正常。现在我实际上不想把dev.yml放在目录中,我想从S3中取出它然后在其中使用变量。像下面的东西 -
- name: Get dev file
s3:
bucket: bucket_name
object: object_name
dest: "dest_directory" ## Here I want the destination to be vars/dev.yml
mode: get
aws_access_key: "{{ s3.aws_access_key }}"
aws_access_key: "{{ s3.aws_secret_key }}"
- name: Include vars file
include_vars: vars/dev.yml
- name: Some other task that uses vars in dev.yml
template: render some template using vars in dev.yml and copy to server
以上实际上不起作用。我该怎么做?
答案 0 :(得分:1)
感谢Konstantin Suvorov寻求帮助。我只需要在我的任务中添加delegate_to
。
- name: Get dev file
s3:
bucket: bucket_name
object: object_name
dest: vars/dev.yml
mode: get
aws_access_key: "{{ s3.aws_access_key }}"
aws_access_key: "{{ s3.aws_secret_key }}"
delegate_to: localhost
- name: Include vars file
include_vars: vars/dev.yml