How to use loop in Ansible playbook

0 votes

Hi Guys,

I want to install multiple software in the remote system. But I don't want to use package modules multiple times. Because it reduces the performance of the system. So how can I create a loop for this task?

Sep 1, 2020 in Ansible by akhtar
• 38,260 points
1,140 views

1 answer to this question.

0 votes

Hi@akhtar,

Sometimes you want to repeat a task multiple times. In computer programming, this is called a loop. Common Ansible loops include changing ownership on several files and/or directories with the file module, creating multiple users with the user module, and repeating a polling step until a certain result is reached. Ansible offers two keywords for creating loops: loop and with_<lookup>. You can see the below example.

- hosts: all
  tasks:
    - package:
        name: "{{ item }}"
        state: present
      loop:
        - "httpd"
        - "python"

answered Sep 1, 2020 by MD
• 95,460 points

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
14,486 views
0 votes
1 answer

How to create a variable in Ansible Playbook?

Hi@akhtar, Variable in playbooks are very similar to using variables in ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
1,337 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,064 views
+2 votes
1 answer
0 votes
1 answer

How to use conditions in Ansible-Playbook?

Hi@akhtar, Traditional programming language usually uses the if-else ...READ MORE

answered Aug 20, 2020 in Ansible by MD
• 95,460 points
1,504 views
0 votes
1 answer

How to use an URL in Ansible Playbook?

Hi@akhtar, You can use the get_url module in ...READ MORE

answered Aug 20, 2020 in Ansible by MD
• 95,460 points
2,214 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP