首页 > 解决方案 > 变量可以引用 vars 文件中的另一个变量吗?

问题描述

我想在 vars 文件本身中构建一个路径(我知道我可以从任务文件中做到这一点)。那将如何运作?

这就是我现在所拥有的:

backup-location: /mnt/cassandra-backup/
schemas-location: schemas/
tokens-location: tokens/ 

我正在从任务文件构建路径:

- name: Create schemas location
  file:
    path: "{{ backup-location }}{{ schemas-location }}"
    state: directory

我想要这样的东西:

backup-location: /mnt/cassandra-backup/
schemas-location: "{{ backup-location }}"schemas/
tokens-location: "{{ backup-location }}"tokens/

任务文件将包含以下内容:

- name: Create schemas location
  file:
    path: "{{ schemas-location }}"
    state: directory

标签: ansible

解决方案


它会这样工作:

schemas-location: "{{ backup-location }}schemas/"
tokens-location: "{{ backup-location }}tokens/"

推荐阅读