9

I am using ansible-galaxy (v2.0.0.2) to install ansible roles that which has the source code on Bitbucket through the requirements.yml file. But I could not checkout the code from bitbucket.org with the private key. Here is the error message, and also my requirements.yml content.

Does any one what's the correct requirements.yml file format for ansible-galaxy 2.0.0.2?

  + ansible-galaxy -vvv install --force --role-file ansible/requirements.yml --roles-path ./ansible/roles

    Using /etc/ansible/ansible.cfg as config file
    Opened /tmp/.ansible_galaxy
    found role {'scm': 'git', 'src': 'git@bitbucket.org:myrepo/nginx.git', 'version': 'latest', 'name': 'nginx'} in yaml file
    Installing role nginx 

     [WARNING]: - nginx was NOT installed successfully: - command git checkout
    latest failed in directory /tmp/tmpQRZc8j (rc=1)
    ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

[requirements.yml]

- name: nginx
  src: git@bitbucket.org:myrepo/nginx.git
  scm: git
  version: latest
  accept_hostkey: yes
  key_file: /tmp/.ssh/id_rsa
RichVel
  • 7,030
  • 6
  • 32
  • 48
ezlee
  • 429
  • 1
  • 5
  • 6

6 Answers6

4

Maybe the scp syntax does not work. The url one might:

ssh://git@bitbucket.org/myrepo/nginx.git

Try, as in this ansible issue:

Direct copy from github clone repo path

git@github.com:geerlingguy/ansible-role-php.git

Actual URL that works

ssh://git@github.com/geerlingguy/ansible-role-php.git

You have to replace the : with a /.
And it needs to be a URL (i.e. contain ://) otherwise ansible-galaxy assumes it's a filesystem path.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

try git+ssh schema

works on ansible-galaxy 2.7.8

ansible-galaxy install git+ssh://bitbucket.org:<username>/<role-name>.git

VictorB
  • 146
  • 5
  • 1
    What about the ssh port number? Ours doesn't run on port 22. – Jason2616321 Jul 29 '19 at 19:57
  • for instance sh "GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no' ansible-galaxy install -f git+ssh://git@bitbucket.services.net:7999/project/ansible-roles -p ./" – VictorB Jul 31 '19 at 12:07
2

If you set "scm: git" underneath the src, galaxy will run "git clone XYZ" where XYZ is your src: field. So, anything you can "git clone XYZ" is what you put in the src field.

- src: ssh://git@bitbucket.internal.com:8899/project/repo-name.git
  scm: git

For the private key, in case it's not your default ssh key, we use ssh-agent(1) (see manpage for usage).

Jason2616321
  • 385
  • 3
  • 9
0

As said by Ansible, if you look in your /tmp/tmpQRZc8j directory you will see that your role has been fetch.

The problem is that you have specified a wrong version argument and ansible is trying to make a git checkout latest which is not possible (unless with a branch or tag named latest).

You have to give an existing branch or tag instead.

Kara
  • 6,115
  • 16
  • 50
  • 57
Ze_Alex
  • 1
  • 1
0

The error is related to the unknown key_file and accept_hostkey attributes in your requirements.yml file.

According to the Ansible documentation, the only available attributes for the requirements.yml file are:

  • src
  • scm
  • version
  • name

You will need to use the ssh config file to configure the ssh-key to use for your private repositories. Here are some helpful links:

U53r
  • 156
  • 1
  • 4
-1

The error will be due to some wrong details given by you in requirements.yml it can be git URL, or version:number or version: branch name

  • 1
    Please change answer to denote the wrong details. Also, please indicate the sources that you have referred to. – Jerry Ajay Oct 22 '20 at 22:54