How can I write variables inside the tasks file in ansible

后端 未结 5 1595
栀梦
栀梦 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条回答
  •  Happy的楠姐
    2021-01-31 07:54

    Variable definitions are meant to be used in tasks. But if you want to include them in tasks probably use the register directive. Like this:

    - name: Define variable in task.
      shell: echo "http://www.my.url.com"
      register: url
    
    - name: Download apache
      shell: wget {{ item }}
      with_items: url.stdout
    

    You can also look at roles as a way of separating tasks depending on the different roles roles. This way you can have separate variables for each of one of your roles. For example you may have a url variable for apache1 and a separate url variable for the role apache2.

提交回复
热议问题