How to include vars file in a vars file with ansible?

后端 未结 3 1344
梦毁少年i
梦毁少年i 2021-02-03 17:49

Is it possible to include a vars file in Ansible into another vars file dynamically?

I.e. I have vars file:

---
definitions:
- { product: web_v2, suite:         


        
相关标签:
3条回答
  • 2021-02-03 18:17

    You can put your servers in the default_step group and those vars will apply to it:

    # inventory file
    [default_step]
    prod2
    web_v2
    

    Then just move your default_step.yml file to group_vars/default_step.yml.

    0 讨论(0)
  • 2021-02-03 18:20

    I know it's an old post but I had the same issue today, what I did is simple : changing my script that send my playbook from my local host to the server, before sending it with maven command, I did this :

    cat common_vars.yml > vars.yml
    cat snapshot_vars.yml >> vars.yml
    # or 
    #cat release_vars.yml >> vars.yml
    mvn ....
    
    0 讨论(0)
  • 2021-02-03 18:30

    Unfortunately, vars files do not have include statements.

    You can either put all the vars into the definitions dictionary, or add the variables as another dictionary in the same file.

    If you don't want to have them in the same file, you can include them at the playbook level by adding the vars file at the start of the play:

    ---
    - hosts: myhosts
    
      vars_files:
        - default_step.yml
    

    or in a task:

    ---
    - hosts: myhosts
    
      tasks:
        - name: include default step variables
          include_vars: default_step.yml
    
    0 讨论(0)
提交回复
热议问题