query on ansible

39 views
Skip to first unread message

mahesh g o

unread,
Apr 17, 2020, 4:54:51 AM4/17/20
to Ansible Project
I have below playbook:

i have put a loop, there are 8 aggr and 4 protocols: this playbook output is like after every 4 loop, it increments aggr and protocols. 

output of the playbook is:

svm1,svm2,svm3,svm4---aggr1 and nfs
svm5,svm6,svm7,svm8---aggr2 and iscsi
svm9,svm10,svm11,svm12---aggr3 and cifs
svm13,svm14,svm15,svm16---aggr4 and fcp

currently the ansible is failing because after 16th loop it is not finding any protocols.

but after 16th loop i want protcols to repeat :

expecting ouput:

svm17,svm18,svm19,svm20---aggr5 and nfs
svm21,svm22,svm23,svm24---aggr6 and iscsi
svm25,svm26,svm27,svm28---aggr7 and cifs
svm29,svm30,svm31,svm32---aggr8 and fcp



- hosts: localhost
  gather_facts: false
  vars_files:
    - /etc/ansible/group_vars/host_vars

  vars:
    aggr:
      - aggr_1
      - aggr_2
      - aggr_3
      - aggr_4
      - aggr_5
      - aggr_6
      - aggr_7
      - aggr_8
    protocols:
      - nfs
      - iscsi
      - cifs
      - fcp
  tasks:
    - name: Create SVM
      na_ontap_svm:
        state: present
        name: "svm{{ item }}"
        root_volume: "svm{{ item }}_root_vol"
        root_volume_aggregate: "{{ aggr[((item|int-1)//4)] }}"
        allowed_protocols: "{{ protocols[(((item)|int-1)//4)] }}"
        root_volume_security_style: mixed
        hostname: "{{ aiqumip }}"
        username: "{{ aiqumusername }}"
        password: "{{ aiqumpassword }}"
        https: false
      with_sequence: start=1 end=32

Stefan Hornburg (Racke)

unread,
Apr 17, 2020, 5:19:23 AM4/17/20
to ansible...@googlegroups.com
There is better way to handle all permutations. Replace with_sequence:

loop: "{{ aggr | product(protocols) | list }}"
loop_control:
index_var: "loop_index"

Then adjust your module parameters:

name: "svm{{ loop_index + 1 }}"
root_volume: "svm{{ loop_index + 1 }}_root_vol"
root_volume_aggregate: "{{ item[0] }}"
allowed_protocols: "{{ item[1] }}"

That should do the trick.

Regards
Racke

--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

mahesh g o

unread,
Apr 17, 2020, 6:55:40 AM4/17/20
to Ansible Project
Thank u very much ...it worked.

I need one more help....the aggr is coming from the playbook1. every time i run that playbook1 individually and i enter the aggr array in  playbook2.
 so how do i get the output of the  playbook1 in the form of array so that i dont have to enter the aggr array in the  playbook2.

playbook2: is the one i shared earlier.


playbook1:
 tasks:
    - name: Create Aggregates and wait 5 minutes until aggregate is online
      na_ontap_aggregate:
        state: absent
        service_state: online
        name: "aggr_{{item }}"
        disk_count: 5
        wait_for_online: True
        nodes: "{{ node[((item|int-1)//2)] }}"
        time_out: 300
        hostname: "{{ aiqumip }}"
        username: "{{ aiqumusername }}"
        password: "{{ aiqumpassword }}"
        validate_certs: false
        with_sequence: start=1 end=8

Stefan Hornburg (Racke)

unread,
Apr 17, 2020, 6:59:18 AM4/17/20
to ansible...@googlegroups.com
On 4/17/20 12:55 PM, mahesh g o wrote:
> Thank u very much ...it worked.
>

You are welcome.

> I need one more help....the aggr is coming from the playbook1. every time i run that playbook1 individually and i enter
> the aggr array in  playbook2.
>  so how do i get the output of the  playbook1 in the form of array so that i dont have to enter the aggr array in the 
> playbook2.
>
> playbook2: is the one i shared earlier.
>

First question would be why do you have two separate playbooks?

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7538e252-68a8-4b49-94c5-19ec6f6c3b59%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7538e252-68a8-4b49-94c5-19ec6f6c3b59%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

mahesh g o

unread,
Apr 17, 2020, 7:08:30 AM4/17/20
to Ansible Project

I am newbie to ansible....i have to create many objects like this(aggr,svm,volumes,luns,policies,network interfaces) so i have created playbook for each objects and thought of stitching it together.

Stefan Hornburg (Racke)

unread,
Apr 17, 2020, 7:13:03 AM4/17/20
to ansible...@googlegroups.com
On 4/17/20 1:08 PM, mahesh g o wrote:
>
> I am newbie to ansible....i have to create many objects like this(aggr,svm,volumes,luns,policies,network interfaces) so
> i have created playbook for each objects and thought of stitching it together.

Yes it is good idea to split up tasks logically, but not a good idea to use separate playbooks:

You can group them in task files,.e.g.

tasks:
- import_tasks: aggr.yml
- import_tasks: svm.yml

Regards
Racke
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/7538e252-68a8-4b49-94c5-19ec6f6c3b59%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/7538e252-68a8-4b49-94c5-19ec6f6c3b59%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/089025ef-6868-4e37-8eaa-44d069e72bf1%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/089025ef-6868-4e37-8eaa-44d069e72bf1%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

mahesh g o

unread,
Apr 17, 2020, 7:18:33 AM4/17/20
to ansible...@googlegroups.com
okay, so if i use them as tasks, will svm.yml takes aggr array from aggr.yml??

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/033d3343-a2f3-3aeb-167c-19440b6d82c4%40linuxia.de.
Reply all
Reply to author
Forward
0 new messages