Ansible: Run multiple commands using command module and with_items

notice the double quotes before and after the {{item}}.


  - name: install an apple
    command: "{{item}}"
    with_items:
     - tar -xvzf /tmp/apple.tar.gz creates=/tmp/apple
     - /tmp/apple/install.sh --default creates=/etc/apple
     - rm -rf /tmp/apple

18 thoughts on “Ansible: Run multiple commands using command module and with_items

  1. With Ansible 1.6.7, this generates an error:

    fatal: [production.example.com] => A variable inserted a new parameter into the module args. Be sure to quote variables if they contain equal signs (for example: “{{var}}”).

    FATAL: all hosts have already failed — aborting

  2. السلامُ عليكم و رحمة اللّهِ و بركاته Bhai

    How do you loop over multiple hosts with multiple commands?


  3. name: To run script
    hosts: your_hostname

    tasks:
    – name: To run multiple commands using command module
    command: “{{item}}”
    with_items:
    – ls -ltr /tmp
    – uptime
    – df -h
    – cat /tmp/abc.txt
    register: reg_out
    – debug: msg=”{{ reg_out.results | map (attribute=’stdout_lines’) | list }}”

  4. In order to encourage as many people as possible to participate, McDonald’s is offering free meal tickets at participating locations in return for survey responses. Check out the requirements for completing the McDonald’s customer satisfaction survey in order to receive free food at the restaurant. mcdfoodforthoughts.org

  5. FitSpresso weight loss Supplement “ingredient list”. The product should be worth the price you are paying. The same logic also applies for foods high in fat, carbohydrates, and calories. My activity level was such that I could not stand still for a long period of time, and had to keep in constant motion.
    https://fitspresso.fitmdblog.com/

  6. Hardee’s and Carl’s Jr. have acknowledged through an online poll that gathering feedback from their consumers is a critical component of their ongoing development and enhancement.
    TellHappyStar.com

  7. I played around with the McDonald’s fruit and yogurt parfait recipe a few times, varying the fruit and toppings each time. However, the recipe I’m sharing with you today is an exact reproduction of the classic McDonald’s breakfast dish.

    McDonald’s Parfait

  8. It’s not required to make a purchase at Lowe’s to participate the lowes.com survey and be eligible to win a $500 monthly sweepstakes. Your chances of winning the Lowe’s 2024/2025 Customer Satisfaction Monthly $500 Survey Sweepstakes would not, however, be increased by a purchase.
    Lowes.Com/Survey

Leave a Reply

Your email address will not be published. Required fields are marked *