কনস্ট্যান্টিন একটি ভাল উত্তর দিয়েছেন; এখানে এটি একটি অতিরিক্ত গন্ধ আছে।
আমি তালিকাগুলি সাধারণত ভেরিয়েবল হিসাবে সংজ্ঞায়িত করব এবং একই ভেরিয়েবলের উপরে দুটি পৃথক লুপ লিখব:
┌─[jamesph@geror] - [~/temp] - [Sat Jan 13, 10:06]
└─[$]> cat loops-1.yml
- hosts: localhost
gather_facts: no
vars:
menu:
- Egg and Spam
- Spam, bacon, sausage and Spam
- Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam
tasks:
- debug:
msg: "We have {{ item }}"
with_items: "{{ menu }}"
- debug:
msg: "I love {{ item }}!"
with_items: "{{ menu }}"
┌─[jamesph@geror] - [~/temp] - [Sat Jan 13, 10:06]
└─[$]> ansible-playbook loops-1.yml
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] **********************************************************************************************************************
TASK [debug] **************************************************************************************************************************
ok: [localhost] => (item=Egg and Spam) => {
"changed": false,
"item": "Egg and Spam",
"msg": "We have Egg and Spam"
}
ok: [localhost] => (item=Spam, bacon, sausage and Spam) => {
"changed": false,
"item": "Spam, bacon, sausage and Spam",
"msg": "We have Spam, bacon, sausage and Spam"
}
ok: [localhost] => (item=Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam) => {
"changed": false,
"item": "Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam",
"msg": "We have Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam"
}
TASK [debug] **************************************************************************************************************************
ok: [localhost] => (item=Egg and Spam) => {
"changed": false,
"item": "Egg and Spam",
"msg": "I love Egg and Spam!"
}
ok: [localhost] => (item=Spam, bacon, sausage and Spam) => {
"changed": false,
"item": "Spam, bacon, sausage and Spam",
"msg": "I love Spam, bacon, sausage and Spam!"
}
ok: [localhost] => (item=Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam) => {
"changed": false,
"item": "Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam",
"msg": "I love Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam!"
}
PLAY RECAP ****************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
এটি ভেরিয়েবল অগ্রাধিকারের সাথে দুর্দান্তভাবে কাজ করে , উদাহরণস্বরূপ, পরিবেশ প্রতি পরিবেশের বিভিন্ন সেট নির্ধারণ করে। যখন দুটি লুপের মধ্যে আপনাকে অন্যান্য অন্যান্য লুপযুক্ত কাজ সম্পাদন করতে হবে তখন এটিও কাজ করে।
loop
একটি উপরblock
ব্লক। এটি অনুরোধ করা হয়েছে বলে মনে হচ্ছে, তবে উত্তর জিএইচ ইস্যু 13262 এর মাধ্যমে প্রত্যাখাত হয়েছে ।:-(