您应使用ansible_play_hosts_all
选择您的主机/组
和hosts.ini
变量在其上循环。
演示:
[group1]
host1 ansible_host=1.2.3.4 ansible_connection=local
host2 ansible_host=2.3.4.5 ansible_connection=local
[group2]
host3 ansible_host=3.4.5.6 ansible_connection=local
host4 ansible_host=4.5.6.7 ansible_connection=local
:
play.yml
---
- hosts: all
gather_facts: no
tasks:
- debug:
msg: |
{% for host in ansible_play_hosts_all -%}
{{ host }},{%- endfor %}
delegate_to: localhost
run_once: yes
:
$ ansible-playbook -i hosts.ini play.yml --limit group1
PLAY [all] *********************************************************************************************************************************
TASK [debug] *******************************************************************************************************************************
ok: [host1 -> localhost] => {
"msg": "host1,host2,\n"
}
PLAY RECAP *********************************************************************************************************************************
host1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$ ansible-playbook -i hosts.ini play.yml --limit host1,host3
PLAY [all] *********************************************************************************************************************************
TASK [debug] *******************************************************************************************************************************
ok: [host1 -> localhost] => {
"msg": "host1,host3,\n"
}
PLAY RECAP *********************************************************************************************************************************
host1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
type Sizes =
| Big
| Medium
| Small
;;
//defines cup/can/bottle with size
type Containment =
| CupDrink of s:Sizes
| CannedDrink of s:Sizes
| BottledDrink of s:Sizes
;;
// defines record for each type for drink
type Coffee = {DrinkName : string; price: double }
type Soda = {DrinkName : string; price: double }
type Brew = {DrinkName : string; price: double }
// union for type of drink
type liquid =
| Coffee of c:Coffee
| Cola of s:Soda
| Beer of b:Brew
;;
let Guiness = Beer {DrinkName = "Guiness"; price = 0.15}
let CocaCola = Cola {DrinkName = "Cola"; price = 0.15}
let smallCup = CupDrink Small // it could be just containment | size
let bigBottle= BottledDrink Big
let findPricePrML(dr:liquid) =
let price = 0.0
match dr with
|Beer(b=h)-> h.price
|Cola(s=h) ->h.price
|Coffee(c=h) -> h.price
|_-> failwith "not found"
// returns size in ML fro each size available // asuming that small bottle,can and cup have same size,//if not another kind of program can be made but it's not part of the assingment
let find size =
match size with
|Big -> 250.00
|Medium -> 125.00
|Small -> 75.00
本文链接:https://www.f2er.com/3165747.html