How to specify range to iterate through an array in ansible
Clash 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.
ansible
add a comment |Â
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.
ansible
add a comment |Â
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.
ansible
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
ansible
edited Sep 11 at 7:37
Rui F Ribeiro
36.8k1273117
36.8k1273117
asked Sep 11 at 7:23
achak01
31
31
add a comment |Â
add a comment |Â
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
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
Thepackage
module is the generic one and should be preferred, but there is also anrpm
and ayum
module if you need to do specific tasks.
â mhutter
Sep 11 at 9:33
add a comment |Â
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
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
Thepackage
module is the generic one and should be preferred, but there is also anrpm
and ayum
module if you need to do specific tasks.
â mhutter
Sep 11 at 9:33
add a comment |Â
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
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
Thepackage
module is the generic one and should be preferred, but there is also anrpm
and ayum
module if you need to do specific tasks.
â mhutter
Sep 11 at 9:33
add a comment |Â
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
- 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
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
Thepackage
module is the generic one and should be preferred, but there is also anrpm
and ayum
module if you need to do specific tasks.
â mhutter
Sep 11 at 9:33
add a comment |Â
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
Thepackage
module is the generic one and should be preferred, but there is also anrpm
and ayum
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password