How to specify range to iterate through an array in ansible

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I want to remove an application on a remote node using ansible. Below is my playbook. How do i provide a range to the uninstall task to repeat till no packages are left.



---



 hosts: all



tasks:
- name: check-packages
shell: rpm -qa | grep -e "^(HPOpr|HPE|HPOv|HPBsm|MIB2Policy|HPOMi)"
register: output

- name: uninstall
shell: rpm -e output.stdout_lines.0 --nodeps


I tried with range operator



 shell: rpm -e output.stdout_lines[:40] --nodeps


But it was not working.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I want to remove an application on a remote node using ansible. Below is my playbook. How do i provide a range to the uninstall task to repeat till no packages are left.



    ---



     hosts: all



    tasks:
    - name: check-packages
    shell: rpm -qa | grep -e "^(HPOpr|HPE|HPOv|HPBsm|MIB2Policy|HPOMi)"
    register: output

    - name: uninstall
    shell: rpm -e output.stdout_lines.0 --nodeps


    I tried with range operator



     shell: rpm -e output.stdout_lines[:40] --nodeps


    But it was not working.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to remove an application on a remote node using ansible. Below is my playbook. How do i provide a range to the uninstall task to repeat till no packages are left.



      ---



       hosts: all



      tasks:
      - name: check-packages
      shell: rpm -qa | grep -e "^(HPOpr|HPE|HPOv|HPBsm|MIB2Policy|HPOMi)"
      register: output

      - name: uninstall
      shell: rpm -e output.stdout_lines.0 --nodeps


      I tried with range operator



       shell: rpm -e output.stdout_lines[:40] --nodeps


      But it was not working.










      share|improve this question















      I want to remove an application on a remote node using ansible. Below is my playbook. How do i provide a range to the uninstall task to repeat till no packages are left.



      ---



       hosts: all



      tasks:
      - name: check-packages
      shell: rpm -qa | grep -e "^(HPOpr|HPE|HPOv|HPBsm|MIB2Policy|HPOMi)"
      register: output

      - name: uninstall
      shell: rpm -e output.stdout_lines.0 --nodeps


      I tried with range operator



       shell: rpm -e output.stdout_lines[:40] --nodeps


      But it was not working.







      ansible






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 11 at 7:37









      Rui F Ribeiro

      36.8k1273117




      36.8k1273117










      asked Sep 11 at 7:23









      achak01

      31




      31




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          - name: uninstall
          package:
          name: " item "
          state: absent
          with_list: " output.stdout_lines "


          Or if you use Ansible 2.5 or newer, replace with_list with loop.



          You can also do it in one go:



          - name: uninstall
          package:
          name: " output.stdout_lines "
          state: absent


          • Documentation on loops

          • Documentation for the package module

          • Documentation on filters





          share|improve this answer






















          • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
            – achak01
            Sep 11 at 8:45










          • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
            – mhutter
            Sep 11 at 9:33










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468188%2fhow-to-specify-range-to-iterate-through-an-array-in-ansible%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          - name: uninstall
          package:
          name: " item "
          state: absent
          with_list: " output.stdout_lines "


          Or if you use Ansible 2.5 or newer, replace with_list with loop.



          You can also do it in one go:



          - name: uninstall
          package:
          name: " output.stdout_lines "
          state: absent


          • Documentation on loops

          • Documentation for the package module

          • Documentation on filters





          share|improve this answer






















          • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
            – achak01
            Sep 11 at 8:45










          • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
            – mhutter
            Sep 11 at 9:33














          up vote
          1
          down vote



          accepted










          - name: uninstall
          package:
          name: " item "
          state: absent
          with_list: " output.stdout_lines "


          Or if you use Ansible 2.5 or newer, replace with_list with loop.



          You can also do it in one go:



          - name: uninstall
          package:
          name: " output.stdout_lines "
          state: absent


          • Documentation on loops

          • Documentation for the package module

          • Documentation on filters





          share|improve this answer






















          • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
            – achak01
            Sep 11 at 8:45










          • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
            – mhutter
            Sep 11 at 9:33












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          - name: uninstall
          package:
          name: " item "
          state: absent
          with_list: " output.stdout_lines "


          Or if you use Ansible 2.5 or newer, replace with_list with loop.



          You can also do it in one go:



          - name: uninstall
          package:
          name: " output.stdout_lines "
          state: absent


          • Documentation on loops

          • Documentation for the package module

          • Documentation on filters





          share|improve this answer














          - name: uninstall
          package:
          name: " item "
          state: absent
          with_list: " output.stdout_lines "


          Or if you use Ansible 2.5 or newer, replace with_list with loop.



          You can also do it in one go:



          - name: uninstall
          package:
          name: " output.stdout_lines "
          state: absent


          • Documentation on loops

          • Documentation for the package module

          • Documentation on filters






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 12 at 17:18

























          answered Sep 11 at 8:17









          mhutter

          567210




          567210











          • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
            – achak01
            Sep 11 at 8:45










          • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
            – mhutter
            Sep 11 at 9:33
















          • Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
            – achak01
            Sep 11 at 8:45










          • The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
            – mhutter
            Sep 11 at 9:33















          Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
          – achak01
          Sep 11 at 8:45




          Thanks a lot. It worked like charm. I was having this misconception that package module will only work for RPM :-) .
          – achak01
          Sep 11 at 8:45












          The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
          – mhutter
          Sep 11 at 9:33




          The package module is the generic one and should be preferred, but there is also an rpm and a yum module if you need to do specific tasks.
          – mhutter
          Sep 11 at 9:33

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468188%2fhow-to-specify-range-to-iterate-through-an-array-in-ansible%23new-answer', 'question_page');

          );

          Post as a guest













































































          xSqCabi,Ygcx7ss3tCRT3WviHIhg INoYUP28gVgmBh,v23cAhDt8tnF1559198As9YIArp 4bMlI
          M61hfJjMg i5 4k70I01b2KkE zWCH,ghl,vcSljzlWp Bhl497AE,EJQXX8lqag2

          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          How many registers does an x86_64 CPU actually have?

          Displaying single band from multi-band raster using QGIS