Gardez un sèche ansite: comment éviter de répéter des variables?
-
21-12-2019 - |
Question
Récemment vient de commencer à utiliser un ansible et j'ai rencontré un problème.Dans l'une de mes structures YAML, j'ai défini quelque chose comme ceci:
---
# 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 me donne une erreur comme celle-ci à partir d'une tâche spécifique:
"boucle récursive détectée dans la chaîne de modèle: {{jenkins.home}} / mises à jour_jenkins.json "
Je l'ai réduit au problème avec le fait que bin_path et mises à jour_path se réfèrent à "home".Y a-t-il un moyen de contourner ceci?Il est un peu craint que j'aurais besoin de définir plusieurs fois "/ opt / jenkins".
La solution
Autant que je sache que ceci est une limitation des variables de Jinja2.Cela travaillait avec l'ancien $ {} et cassé depuis 1,4.Je ne sais pas si ils ont réparé cela en 1.5.
Ma solution temporaire retirerait la maison de "Jenkins"
---
# file: main.yml
#
# Jenkins variables for installation and configuration
# Installation directory
jenkins_home: '/opt/jenkins'
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
# 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'
Autres conseils
Cela devrait le faire:
bin_path: "{{ jenkins['home'] }}/jenkins-cli.jar"