如果已经安装了角色,如何使 ansible-provisioner 不出错

问题描述 投票:0回答:1

我正在使用 Ansible Packer 配置程序 在 Packer 启动的一个或多个 AWS 实例上执行剧本,以构建自定义 Amazon 托管映像 (AMI)。

实例是并行启动的,但问题是当我执行 Ansible 配置程序时,如果它尝试重新安装已安装的角色并要求我使用

--ignore-errors
,则会出错。

amazon-ebs.build_ami: [WARNING]: - ansible_role_<REDACTED> was NOT installed successfully: the
amazon-ebs.build_ami: Starting galaxy role install process
amazon-ebs.build_ami: specified role ansible_role_<REDACTED> appears to already exist. Use
amazon-ebs.build_ami: --force to replace it.
amazon-ebs.build_ami: - extracting ansible_role_<REDACTED> to <REDACTED>/.ansible/roles/ansible_role_<REDACTED>
amazon-ebs.build_ami: ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
==> amazon-ebs.build_ami: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs.build_ami: Terminating the source AWS instance...

有什么方法可以阻止配置者尝试多次安装角色或将

--ignore-errors
发送到配置者使用的 Ansible Galaxy 命令吗?

我尝试使用

galaxy_command
选项进行设置,但无法弄清楚。

我还尝试设置自定义

roles_path
collections_path
,但配置者仍然将角色和集合安装到 Ansible 指定的默认位置。

我希望继续并行构建 AMI。

这是构建配置的简化版本:

build {
  dynamic "source" {
    for_each = local.images
    labels   = ["amazon-ebs.ami"]

    content {
      name       = "build_${source.value.value_one}_${source.value.value_two}_${source.value_three}"
      value_one   = source.value.value_one
      value_two = source.value.value_two
      value_three   = source.value.value_three
    }
 }

这是 ansible 配置程序配置的简化版本:

provisioner "ansible" {
    playbook_file  = "playbook.yml"
    galaxy_file    = "requirements.yml"
    use_proxy      = false

    ansible_env_vars = [
      "ANSIBLE_FORCE_COLOR=1",                 # Force colored output
      "ANSIBLE_PYTHON_INTERPRETER=auto_silent" # Silence warning about Python discovery
    ]

    extra_arguments = [
      "--extra-vars", "\"ansible_python_interpreter=/usr/bin/env python3\"", # Find Python 3 on PATH
    ]
  }

我希望有人能给我一种方法来使用

--ignore-errors
(这并不理想)或其他方法来解决这个问题。

amazon-web-services ansible packer hashicorp-packer packer-builder
1个回答
0
投票

由于与缓存相关的问题,这是

ansible-galaxy
packer-plugin-ansible
之间的已知冲突。我通常用
galaxy_force_install
参数解决这个问题:

provisioner "ansible" {
  playbook_file        = "playbook.yml"
  galaxy_file          = "requirements.yml"
  galaxy_force_install = true
  use_proxy            = false

  ansible_env_vars = [
    "ANSIBLE_FORCE_COLOR=1",                 # Force colored output
    "ANSIBLE_PYTHON_INTERPRETER=auto_silent" # Silence warning about Python discovery
  ]

  extra_arguments = [
    "--extra-vars", "\"ansible_python_interpreter=/usr/bin/env python3\"", # Find Python 3 on PATH
  ]
}

这有可能仍然会给您带来角色和集合依赖性问题,在这种情况下,我建议全力使用

galaxy_force_with_deps
:

provisioner "ansible" {
  playbook_file          = "playbook.yml"
  galaxy_file            = "requirements.yml"
  galaxy_force_with_deps = true
  use_proxy              = false

  ansible_env_vars = [
    "ANSIBLE_FORCE_COLOR=1",                 # Force colored output
    "ANSIBLE_PYTHON_INTERPRETER=auto_silent" # Silence warning about Python discovery
  ]

  extra_arguments = [
    "--extra-vars", "\"ansible_python_interpreter=/usr/bin/env python3\"", # Find Python 3 on PATH
  ]
}

您可以在文档中查看有关这些可选参数的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.