How can I write variables inside the tasks file in ansible

后端 未结 5 1552
栀梦
栀梦 2021-01-31 07:26

I have this play.yml

---
- hosts: 127.0.0.1
  connection: local
  sudo: false

  tasks:
     - include: apache.yml

My Apache look

5条回答
  •  故里飘歌
    2021-01-31 07:50

    NOTE: Using set_fact as described below sets a fact/variable onto the remote servers that the task is running against. This fact/variable will then persist across subsequent tasks for the entire duration of your playbook.

    Also, these facts are immutable (for the duration of the playbook), and cannot be changed once set.


    ORIGINAL ANSWER

    Use set_fact before your task to set facts which seem interchangeable with variables:

    - name: Set Apache URL
      set_fact:
        apache_url: 'http://example.com/apache'
    
    - name: Download Apache
      shell: wget {{ apache_url }}
    

    See http://docs.ansible.com/set_fact_module.html for the official word.

提交回复
热议问题