在 Jenkins 管道中的 shell 命令中执行时,Ansible ad-hoc 库存不起作用?

Ansible ad-hoc inventory not working when executed in a shell command in a Jenkins pipeline?

Ansible v2.11.x

我有一个 Jenkins 管道可以执行此操作。所有 $VARIABLES 都是从作业参数传入的。

  withCredentials([string(credentialsId: "VAULT_PASSWORD", variable: "VAULT_PASSWORD")]) {
    stage("Configure $env.IP_ADDRESS") {
      sh """
        ansible-playbook -i \"$env.IP_ADDRESS,\" \
                         -e var_host=$env.IP_ADDRESS \
                         -e web_branch=$env.WEB_BRANCH \
                         -e web_version=$env.WEB_VERSION \
                         site.yml
      """
    }
  }

我的剧本是这样的

---
- hosts: "{{ var_host | default('site') }}"

  roles:
     - some_role

我有一个 groups_vars/all.yml 文件,供此类临时库存使用。当我 运行 管道时,我只是得到以下内容,而 运行 什么都不做

22:52:29  + ansible-playbook -i "10.x.x.x," -e var_host=10.x.x.x -e web_branch=development -e web_version=81cdedd6fe-20210811_2031 site.yml
22:52:31  [WARNING]: Could not match supplied host pattern, ignoring: 10.x.x.x

如果我继续构建节点并执行完全相同的命令,它就可以工作。我也可以在我的 Mac 上执行相同的命令,它也有效。

那么为什么临时库存在管道中执行时不起作用?

This post给了我一个线索

对我有用的正确语法是

  withCredentials([string(credentialsId: "VAULT_PASSWORD", variable: "VAULT_PASSWORD")]) {
    stage("Configure $env.IP_ADDRESS") {
      sh """
        ansible-playbook -i $env.IP_ADDRESS, \
                         -e var_host=$env.IP_ADDRESS \
                         -e web_branch=$env.WEB_BRANCH \
                         -e web_version=$env.WEB_VERSION \
                         site.yml
      """
    }
  }