使用ansible的helm扩展覆盖values.yml

Dan*_*iel 3 ibm-connections ansible docker kubernetes-helm

我想创建一个剧本来安装 IBM ZIP 存档提供的外部 helm 图表。我们需要用自定义值覆盖values.yml中的一些值(例如主机到docker注册表)。

IBM value.yml 中的示例

image:
  pullPolicy: IfNotPresent
  repository: artifactory.swg.usma.ibm.com:6562
Run Code Online (Sandbox Code Playgroud)

由于 IBM 设置了非公共存储库,因此我将图像(从 IBM 版本下载)上传到我的自定义注册表registry.example.com,并希望将其设置在我的剧本中:

- name: CNX Bootstrap
  helm:
    # Port forwarding from tiller to localhost
    host: localhost
    state: present
    name: bootstrap-test
    namespace: "{{namespace}}"
    chart: 
      name: bootstrap
      source:
        type: directory
        location: /install/component-pack/IC-ComponentPack-6.0.0.7/microservices_connections/hybridcloud/helmbuilds/bootstrap
    values: 
      image.repository: "registry.example.com"
Run Code Online (Sandbox Code Playgroud)

这不起作用,pod 日志显示:

无法拉取映像“artifactory.swg.usma.ibm.com:6562/bootstrap:20190204-022029”:rpc 错误:代码 = 未知 desc = 获取https://artifactory.swg.usma.ibm.com:6562/v1 /_ping : 服务不可用

所以它仍然使用错误的注册表,并且我的自定义values似乎被忽略。使用helmcli,我可以使用--set如下开关进行覆盖:

helm install --name=bootstrap /install/component-pack/IC-ComponentPack-6.0.0.7/microservices_connections/hybridcloud/helmbuilds/bootstrap-0.1.0-20190204-022029.tgz --set image.repository=registry.example.com
Run Code Online (Sandbox Code Playgroud)

如何像--setAnsible 中的开关那样覆盖图表的值?

模块文档不提供任何信息。我才发现用的pyhelm 。但我找不到覆盖默认值的方法。

yan*_*ver 5

当 PyHelm 获取从 Ansible 图表定义传递的值时,它会作为字典传递,并将其转换为 yaml。Tiller(Helm 的服务器端组件)期望传递的 yaml 值保持嵌套状态。因此,您需要将它们作为嵌套字典存储在 Ansible 定义中。

在你的情况下,它看起来像:

- name: CNX Bootstrap
  helm:
    # Port forwarding from tiller to localhost
    host: localhost
    state: present
    name: bootstrap-test
    namespace: "{{namespace}}"
    chart: 
      name: bootstrap
      source:
        type: directory
        location: /install/component-pack/IC-ComponentPack-6.0.0.7/microservices_connections/hybridcloud/helmbuilds/bootstrap
    values: 
      image:
        repository: "registry.example.com"
Run Code Online (Sandbox Code Playgroud)