简体   繁体   中英

AWX/TOWER How to manually pass multiple hosts to ansible tower template at runtime?

I would like to insert some hosts dynamically at the runtime of playbook/template execution.

At the moment, I can use the survey, however, I can only successfully insert just one server. When I try to put more than 1 server (list of 2 or more hosts), the playbook does not understand.

How can I dynamically place more than one server, at template runtime?

Just ie:

> ---
> - hosts: localhost   
    connection: local   
    gather_facts: false
> 
>   tasks:
>     - name: add hosts from extra-vars to "temp" group
>       add_host:
>         name: "{{ item }}"
>         groups: temp        
>       
> - hosts: temp   
    gather_facts: true
> 
>   tasks:
> 
>     - name: Show uptime
>       shell: uptime
>       register: uptime
> 
>     - name: Show results
>       debug:
>         msg: "{{ uptime.stdout }}"
> 
> 

var item = host1 host2 host3

Assuming you have an inventory that contains all the dynamic hosts, one "cleaner" way to do it is :

  • in your playbook, remove the first play then change hosts to all
  • in your template use the inventory that contains all the potential hosts you'll add
  • in your template, check the "prompt on launch" option on the "limit" field

Now when you launch your template it will ask you to enter the targets hosts dynamically. Enter the needed hosts separated by comma. It also acceptes host patterns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM