简体   繁体   English

剧本中的 Ansible 保险库具有错误变量“tomcat_password”未定义

[英]Ansible vault in playbook having error variable 'tomcat_password' is undefined

I am newbie to ansible.我是 ansible 的新手。 I am trying to perform some deployment task in 142.23.9.23 via help of ansible using jenkins.我正在尝试使用 jenkins 通过 ansible 的帮助在 142.23.9.23 中执行一些部署任务。 I am hitting below error FAILED: => {"msg", "The field 'become_pass' has an invalid value. which includes an undefined variable: The error was. 'tomcat_password' is undefined"}.我遇到错误失败:=> {“msg”,“字段'become_pass'的值无效。其中包括一个未定义的变量:错误是。'tomcat_password'未定义”}。

I am open to new suggestion as well.我也愿意接受新的建议。

Below is the details以下是详细信息

Directory目录

ansible
   |---- group_vars
           |---- MAIN
                  |---- vault.yml
   |---- hosts
           |---- host-details.yml
   |---- roles
   |----- my-playbook.yml

my-playbook.yml我的剧本.yml

- hosts: app-server
  tasks:
    - name: Print message
      debug: msg="test playbook version ansible_host = {{ ansible_host }}, ansible_ssh_user = {{ansible_ssh_user}}"
  vars_files:
    - group_vars/COMMON/vault.yml

host-details.yml主机详细信息.yml


[app-server]
142.23.9.23 ansible_host=142.23.9.23 ansible_ssh_user=myuser ansible_become=yes ansible_become_user=myuser ansible_become_pass='{{ tomcat_password }}'

ansible-vault edit vault.yml ansible-vault 编辑 vault.yml

tomcat_password: password1
jenkins_password: password2

I think you should ensure that you understand how group_vars and host_vars works: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html我认为您应该确保您了解 group_vars 和 host_vars 的工作原理: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.ZFC35FDC70D5FC69D269883A82

The point here, is that your app-server is a group, not an host, and it seems to not being in the group MAIN nor COMMON.这里的重点是您的应用服务器是一个组,而不是主机,而且它似乎不在组 MAIN 或 COMMON 中。 You don't have to force the inclusion of vars from group_vars, adding hosts in the groups is enough.您不必强制包含来自 group_vars 的 var,在组中添加主机就足够了。

Your inventory should be more like this:您的库存应该更像这样:

[app-server]
142.23.9.23 ansible_host=142.23.9.23 ansible_ssh_user=myuser ansible_become=yes ansible_become_user=myuser ansible_become_pass='{{ tomcat_password }}'

[COMMON:children]
app-server

[MAIN:children]
app-server

But anyway, please read carefully how to make an inventory as it will solve most of your problems.但无论如何,请仔细阅读如何制作库存,因为它将解决您的大部分问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM