How can I write variables inside the tasks file in ansible

后端 未结 5 1543
栀梦
栀梦 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:47

    In Your example, apache.yml is tasklist, but not playbook

    In depends on desired architecture, You can do one of:

    1. Convert apache.yml to role. Then define tasks in roles/apache/tasks/mail.yml and variables in roles/apache/defaults/mail.yml (vars in defaults can be overriden when role applied)

    2. Set vars in play.yml playbook

    play.yml

    ---
    - hosts: 127.0.0.1
      connection: local
      sudo: false
    
      vars:
        url: czxcxz
    
      tasks:
         - include: apache.yml
    

    apache.yml

    - name: Download apache
      shell: wget {{url}} 
    

提交回复
热议问题