0

I have a YAML file filled with variables that I need to download with an Ansible role and this file lives within GitHub.

In a temporary hacky way I first run a curl command to get the download URL using this URL: https://<PAT>@api.github.com/repos/<org>/<repoName>/contents/<filePath>/<fileName>.yml

The download URL I get from the above command is: https://raw.githubusercontent.com/<org>/<repoName>/develop/<filePath>/<fileName>.yml?token=<token>

My Ansible role looks like:

- name: Download vars file from VCS
  get_url:
    url: '<downloadUrl>'
    dest: '{{ playbook_dir }}/<fileName>.yml'
  delegate_to: localhost

This task fails saying:

15:24:43  TASK [get_vars : Download vars file from VCS] **********************************
15:24:43  Request failed
15:24:43  
15:24:43  
15:24:43  NO MORE HOSTS LEFT *************************************************************

I am running this fine using an Azure DevOps with the URL: https://dev.azure.com/<org>/<repoName>/_apis/git/repositories/<repoName>/items?versionType=branch&version=develop&path=<filePath>/<fileName>.yml

How do I download a file from my GitHub repository to then be able to use the variables within?

torek
  • 448,244
  • 59
  • 642
  • 775
agw2021
  • 266
  • 2
  • 22
  • You appear to be asking multiple questions at once, and you also have failed to read the [how to ask](https://stackoverflow.com/help/how-to-ask) page, and the [MCVE](https://stackoverflow.com/help/mcve) section – mdaniel Sep 29 '22 at 02:42
  • You can't load any new file contains variables or tasks at execution time, because Ansible loads them only at the beginning. For example, if you change some task while the playbook is running, Ansible will ignore that change. – Khaled Sep 29 '22 at 06:38
  • 2
    @Khaled that is for sure not true, that's the very thing [`import_tasks:`](https://docs.ansible.com/ansible/6/collections/ansible/builtin/import_tasks_module.html) is designed to do – mdaniel Sep 29 '22 at 19:14

0 Answers0