packer-plugin-ansible icon indicating copy to clipboard operation
packer-plugin-ansible copied to clipboard

Install ansible roles and collections at the same time from the same requirements.yml file?

Open jrobison-sb opened this issue 1 year ago • 3 comments

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

It should be possible to install roles and collections together at the same time if you have both roles and collections in a requirements.yml file.

Use Case(s)

It should be possible to install roles and collections together at the same time if you have both roles and collections in a requirements.yml file.

This comment describes the use case in more depth: https://github.com/hashicorp/packer-plugin-ansible/issues/32#issuecomment-1087700918

Potential configuration

If I do it like this:

  provisioner "ansible-local" {
    staging_directory       = "/home/ubuntu/.ansible"
    clean_staging_directory = true
    extra_arguments = [
      "--become",
      "--vault-password-file /etc/ansible/vault_secret_file",
      "--extra-vars '${jsonencode({ in_ci = true })}'",
    ]
    galaxy_file   = "ansible/requirements.yml"
    playbook_dir  = "ansible/"
    playbook_file = "ansible/my_playbook.yml"
  }
}

Then the resulting ansible-galaxy command output will look like this:

    amazon-ebs.my_playbook: Executing Ansible Galaxy: cd /home/ubuntu/.ansible && ansible-galaxy install -r /home/ubuntu/.ansible/requirements.yml -p /home/ubuntu/.ansible/roles
==> amazon-ebs.my_playbook: [WARNING]: The requirements file '/home/ubuntu/.ansible/requirements.yml'
==> amazon-ebs.my_playbook: contains collections which will be ignored. To install these collections run
==> amazon-ebs.my_playbook: 'ansible-galaxy collection install -r' or to install both at the same time run
==> amazon-ebs.my_playbook: 'ansible-galaxy install -r' without a custom install path.
    amazon-ebs.my_playbook: Starting galaxy role install process

It should be possible to do what is described in that output and use 'ansible-galaxy install -r' without a custom install path.

Currently I have to work around it like this:

  # The ansible-local provisioner below doesn't install Ansible collections,
  # it only installs Ansible roles. So we need to upload the requirements.yml
  # file and install collections manually.
  # https://github.com/hashicorp/packer-plugin-ansible/issues/32#issuecomment-1087700918
  provisioner "file" {
    source = "ansible/requirements.yml"
    destination = "/tmp/requirements.yml"
  }

  # The ansible-local provisioner below doesn't install Ansible collections,
  # it only installs Ansible roles. So we need to upload the requirements.yml
  # file and install collections manually.
  # https://github.com/hashicorp/packer-plugin-ansible/issues/32#issuecomment-1087700918
  provisioner "shell" {
    remote_folder  = "/home/ubuntu"
    inline_shebang = "/bin/bash -e"
    inline = [
      "ansible-galaxy install -r /tmp/requirements.yml"
    ]
  }

  provisioner "ansible-local" {
    staging_directory       = "/home/ubuntu/.ansible"
    clean_staging_directory = true
    extra_arguments = [
      "--become",
      "--vault-password-file /etc/ansible/vault_secret_file",
      "--extra-vars '${jsonencode({ in_ci = true })}'",
    ]
    galaxy_file   = "ansible/requirements.yml"
    playbook_dir  = "ansible/"
    playbook_file = "ansible/my_playbook.yml"
  }
}

Potential References

jrobison-sb avatar May 09 '24 13:05 jrobison-sb

@saurabhrajguru is this issue still valid with latest ansible-devops collection?

andrercm avatar Apr 11 '24 12:04 andrercm

@andrercm I got same error with latest ansible-devops collection (19.0.0). Modifying ICSP (#1264) didn't worked for me so I had to skip Grafana installation.

export CLUSTER_MONITORING_INCLUDE_GRAFANA=False

SalaryTheft avatar Apr 12 '24 07:04 SalaryTheft

Merging duplicate issue https://github.com/ibm-mas/ansible-devops/issues/1264 into this and closing 1264.

Hello,

the Grafana operator gets its dependencies from ghcr.io/grafana and docker.io/grafana

These are not in redhat-catalogs.yml.j2 and thus the installation fails

For example I had to add the following entries to the generated ICSP:

    - mirrors:
        - 'registry.gym.lan:8443/grafana'
      source: ghcr.io/grafana
    - mirrors:
        - 'registry.gym.lan:8443/grafana'
      source: docker.io/grafana

durera avatar Apr 26 '24 13:04 durera

Fixed in https://github.com/ibm-mas/ansible-devops/releases/tag/20.1.0 with https://github.com/ibm-mas/ansible-devops/pull/1314

stonepd avatar May 22 '24 07:05 stonepd