How to pull a variable file from S3 in Ansible

Saurabh Goyal

My requirement is that I want to dynamically include a variable file in my Ansible script. I can do that by putting following in my ansible task-

- name: Include vars file
  include_vars: vars/dev.yml

- name: Some other task
  cp: copy something

Above works if I keep the dev.yml in my vars directory. Now I actually do not want to put the dev.yml in the directory, I want to pull it from S3 and then use the variable in it. Something like below-

- 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

The above will actually not work. How do I do this?

Saurabh Goyal

Thanks Konstantin Suvorov for help. I just needed to add delegate_to in my task.

- 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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pull specific values from ansible facts

From Dev

How to read file from s3?

From Dev

How to use Ansible fact variable in role's variable file

From Dev

How to call list like values from the variable file in ansible

From Dev

How to include a variable file in Ansible?

From Dev

Ansible: how to construct a variable from another variable and then fetch it's value

From Dev

Laravel getID3 unable to pull file from S3

From Dev

Ansible pull from svn

From Dev

how to pull google drive file id's from list python?

From Dev

How to pull only certain csv's and concat the data from s3?

From Dev

Ansible: Copy file from path in Environment Variable

From Dev

How to pull or read image in Django from AWS s3 bucket for OpenCV to process?

From Dev

How to assign a computed variable from one yml file to another yml file in Ansible?

From Java

How to move a file from one S3 Client to another S3 client

From Dev

How to solve s3 access denied on file added to s3 bucket from another account?

From Dev

How do i pull from insecure docker registry with ansible?

From Dev

How to pull deeply nested data from a dictionary in ansible

From Dev

How to upload file from my local storage into S3?

From Dev

Python: how to download a file from an S3 bucket

From Dev

How to download media file from S3 bucket in Django

From Dev

How to generate URL to download file from S3 bucket

From Dev

how to write the object retrieved from s3 to a file?

From Java

How to download GZip file from S3?

From Dev

How to read file from s3 with uproot?

From Dev

How to delete a file with an empty name from S3

From

How to read CSV file from S3

From Dev

How to parse an AWS S3 file from a Lambda function

From Dev

How to access a file on Amazon S3 from the Command Line?

From Dev

How to read a file from s3 in EMR?

Related Related

  1. 1

    How to pull specific values from ansible facts

  2. 2

    How to read file from s3?

  3. 3

    How to use Ansible fact variable in role's variable file

  4. 4

    How to call list like values from the variable file in ansible

  5. 5

    How to include a variable file in Ansible?

  6. 6

    Ansible: how to construct a variable from another variable and then fetch it's value

  7. 7

    Laravel getID3 unable to pull file from S3

  8. 8

    Ansible pull from svn

  9. 9

    how to pull google drive file id's from list python?

  10. 10

    How to pull only certain csv's and concat the data from s3?

  11. 11

    Ansible: Copy file from path in Environment Variable

  12. 12

    How to pull or read image in Django from AWS s3 bucket for OpenCV to process?

  13. 13

    How to assign a computed variable from one yml file to another yml file in Ansible?

  14. 14

    How to move a file from one S3 Client to another S3 client

  15. 15

    How to solve s3 access denied on file added to s3 bucket from another account?

  16. 16

    How do i pull from insecure docker registry with ansible?

  17. 17

    How to pull deeply nested data from a dictionary in ansible

  18. 18

    How to upload file from my local storage into S3?

  19. 19

    Python: how to download a file from an S3 bucket

  20. 20

    How to download media file from S3 bucket in Django

  21. 21

    How to generate URL to download file from S3 bucket

  22. 22

    how to write the object retrieved from s3 to a file?

  23. 23

    How to download GZip file from S3?

  24. 24

    How to read file from s3 with uproot?

  25. 25

    How to delete a file with an empty name from S3

  26. 26

    How to read CSV file from S3

  27. 27

    How to parse an AWS S3 file from a Lambda function

  28. 28

    How to access a file on Amazon S3 from the Command Line?

  29. 29

    How to read a file from s3 in EMR?

HotTag

Archive