D
D
Dmitry2018-01-07 01:45:52
Ansible
Dmitry, 2018-01-07 01:45:52

How to set default values ​​of a variable?

The idea is this: depending on the ip of the host, throw a certain file (not yet implemented) into a specific folder (they differ on all hosts).

---
- hosts: test
  tasks:
  - include: tasks.yml
  - name: Include vars
    include_vars:
      file: vars.yml
  - name: Debug
    debug: msg={{ console_path }}

tasks.yml
---
 - set_fact:
      console_path = "/var/www/folder1"
   when: 
      ansible_default_ipv4.address == "1.2.3.4"
vars.yml
---
console_path: "/var/www/folder"

I read about the order of setting variables, and thought about how to still set the variable depending on the host: in msg, the pre-installed console_path: "/var/www/folder" always hangs, regardless of ip? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2018-01-07
@dmitrydeco

Set it at the host description level and not in the playbook

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question