保持Ansible干燥:如何避免重复变量?

保持Ansible干燥:如何避免重复变量?,ansible,ansible-playbook,Ansible,Ansible Playbook,最近刚开始使用Ansible,我遇到了一个问题。在我的一个YAML结构中,我定义了如下内容: --- # file: main.yml # # Jenkins variables for installation and configuration jenkins: debian: # Debian repository containing Jenkins and the associated key for accessing the repository repo:

最近刚开始使用Ansible,我遇到了一个问题。在我的一个YAML结构中,我定义了如下内容:

---
# file: main.yml
#
# Jenkins variables for installation and configuration

jenkins:
  debian:
    # Debian repository containing Jenkins and the associated key for accessing the repository
    repo: 'deb http://pkg.jenkins-ci.org/debian binary/'
    repo_key: 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key'

    # Dependencies needed for Jenkins to run properly
    dependencies:
      - 'openjdk-7-jdk'
      - 'git-core'
      - 'curl'

  port: 8080

  # Installation directory
  home: '/opt/jenkins'

  # Path to the location of the main Jenkins-cli binary
  bin_path: '{{jenkins.home}}/jenkins-cli.jar'

  # Path to the location of the Jenkins updates file
  updates_path: '{{jenkins.home}}/updates_jenkins.json'
Ansible给出了一个特定任务中的类似错误:

“在模板字符串中检测到递归循环: {{jenkins.home}/updates_jenkins.json“


我已经把它缩小到了问题所在,即bin_路径和updates_路径都指向“home”。有办法解决这个问题吗?我需要多次定义“/opt/jenkins”,这有点糟糕。

据我所知,这是jinja2变量的限制。它使用的是旧的${},从1.4开始就坏了。我不确定他们是否在1.5中解决了这个问题

我的临时解决方案是从“詹金斯”家搬回家

这应该做到:

bin_path: "{{ jenkins['home'] }}/jenkins-cli.jar"

这仍然是1.5中的一个问题。我基本上用samw的方式解决了这个问题。这个答案已经有2年了。有没有新的方法来实现这一点?由Ansible支持的东西?谢谢我正在使用2.0。。。我敢肯定,仍然没有更好的解决办法。我希望我错了!这仍然是
2.4
中的一个问题。这仍然是2.8中的一个问题
bin_path: "{{ jenkins['home'] }}/jenkins-cli.jar"