Get_url won't get the raw file, but html

I have a bitbucket raw file

https://devtools/bitbucket/projects/INA/repos/config/raw/etcd/dotfiles/.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# Bash prompt
export PS1='\u@\h:\w> '

# User specific aliases and functions
test -s ~/.alias && . ~/.alias || true
 
# import postgres environment
test -s /opt/custom/etcd/bin/.etcd.env && . /opt/custom/etcd/bin/.etcd.env || true
 
# set encoding and charset
LANG=de_DE.UTF-8
LC_MESSAGES=en_US.UTF-8
export LANG LC_MESSAGES
 
# define charset for less
export LESSCHARSET=utf-8

and a TASK like

  - name: get dotfiles from bitbucket
    delegate_to: localhost
    ansible.builtin.get_url:
      url: "{{ dotfiles_pull.src }}"
      dest: "{{ dotfiles_pull.dest }}"
    loop:
      - { 'src': "https://devtools/bitbucket/projects/INA/repos/config/raw/etcd/dotfiles/.bashrc",  'dest': ../temp/etcd_bashrc }
    loop_control:
      loop_var: "dotfiles_pull"

resulting into a downloaded file like

 <!DOCTYPE html><html lang="en" data-theme="dark:dark light:light" data-color-mode="light"  ><head><meta charset="utf-8"><meta http-equiv=    "X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width"><title>Log in - Bitbucket</title><script>
  1 window.WRM=window.WRM||{};window.WRM._unparsedData=window.WRM._unparsedData||{};window.WRM._unparsedErrors=window.WRM._unparsedErrors||{}    ;
  2 WRM._unparsedData["com.atlassian.bitbucket.server.bitbucket-webpack-INTERNAL:user-keyboard-shortcuts-enabled.data"]="true";
  3 WRM._unparsedData["com.atlassian.analytics.analytics-client:programmatic-analytics-init.programmatic-analytics-data-provider"]="false";
  4 WRM._unparsedData["com.atlassian.plugins.atlassian-plugins-webresource-plugin:context-path.context-path"]="\u0022/bitbucket\u0022";
  5 WRM._unparsedData["com.atlassian.plugins.atlassian-clientside-extensions-runtime:runtime.atlassianDevMode"]="false";
...

so, I am getting the html of the site rather then to content of the raw file. Any idea what I am doing wrong?

It looks like it is asking for authentication? Does curl on the URL return the file or a login page?

1 Like

thx, that hint was spot on.

this is how I could make it work

  delegate_to: localhost
  ansible.builtin.get_url:
    url: "{{ dotfiles_pull.src }}"
    dest: "{{ dotfiles_pull.dest }}"
    url_username: "{{ bb_user }}"
    url_password: "{{ bb_password }}"
    force_basic_auth: true
  loop:
    - { 'src': "{{ bb_etcd_config_repo }}dotfiles/.bashrc", 'dest': "{{ postgres_download_dir }}/etcd_bashrc" }   ### wip
  loop_control:
    loop_var: "dotfiles_pull"

the relevant bits

    url_username: "{{ bb_user }}"
    url_password: "{{ bb_password }}"
    force_basic_auth: true