|
| 1 | +# Title: create_volume_and_share.yaml |
| 2 | + |
| 3 | +--- |
| 4 | +- name: Playbook to create a volume and a CIFS share that points to it on an FSx for ONTAP file system. |
| 5 | + hosts: localhost |
| 6 | + collections: |
| 7 | + - netapp.ontap |
| 8 | + - amazon.aws |
| 9 | + gather_facts: false |
| 10 | + vars_files: |
| 11 | + - variables.yaml |
| 12 | + vars: |
| 13 | + use_lambda: false |
| 14 | + |
| 15 | + tasks: |
| 16 | + - name: Ensure required variables are set. |
| 17 | + fail: |
| 18 | + msg: "Required variable {{item}} has not been provided." |
| 19 | + when: vars[item] is undefined |
| 20 | + loop: |
| 21 | + - volume_name |
| 22 | + - volume_size |
| 23 | + - vserver |
| 24 | + - secret_name |
| 25 | + - fsxn_hostname |
| 26 | + # |
| 27 | + # Give default values to optional variables if they are not defined |
| 28 | + - name: Set security_style to ntfs if not provided. |
| 29 | + set_fact: |
| 30 | + security_style: "ntfs" |
| 31 | + when: security_style is not defined |
| 32 | + |
| 33 | + - name: Set aggr to 'aggr1' if not provided. |
| 34 | + set_fact: |
| 35 | + aggr: "aggr1" |
| 36 | + when: aggr is not defined |
| 37 | + |
| 38 | + - name: Set volume_type to "rw" if not provided. |
| 39 | + set_fact: |
| 40 | + volume_type: "rw" |
| 41 | + when: volume_type is not defined |
| 42 | + |
| 43 | + - name: Set use_lambda to true if lambda_function_name is provided. |
| 44 | + set_fact: |
| 45 | + use_lambda: true |
| 46 | + when: lambda_function_name is defined |
| 47 | + |
| 48 | + - name: Set aws_profile to "default" if not provided. |
| 49 | + set_fact: |
| 50 | + aws_profile: "default" |
| 51 | + when: aws_profile is not defined |
| 52 | + |
| 53 | + - name: Set junction_path to "/<volume_name>" if not provided. |
| 54 | + set_fact: |
| 55 | + junction_path: "/{{ volume_name }}" |
| 56 | + when: junction_path is not defined |
| 57 | + |
| 58 | + - name: Set share_name to "<volume_name>" if not provided. |
| 59 | + set_fact: |
| 60 | + share_name: "{{ volume_name }}" |
| 61 | + when: share_name is not defined |
| 62 | + |
| 63 | + - name: Ensure that aws_region has been provided if use_lambda is true. |
| 64 | + fail: |
| 65 | + msg: "aws_region must be defined when use_lambda is true." |
| 66 | + when: use_lambda and aws_region is not defined |
| 67 | + |
| 68 | + - name: Set aws_region to "" if not set at this point. |
| 69 | + set_fact: |
| 70 | + aws_region: "" |
| 71 | + when: aws_region is not defined |
| 72 | + |
| 73 | + - name: Set lambda_function_name to "" if not set at this point. |
| 74 | + set_fact: |
| 75 | + lambda_function_name: "" |
| 76 | + when: lambda_function_name is not defined |
| 77 | + |
| 78 | + - name: Get username and password from AWS secret. |
| 79 | + set_fact: |
| 80 | + username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}" |
| 81 | + password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}" |
| 82 | + no_log: true |
| 83 | + |
| 84 | + - name: Create the volume |
| 85 | + netapp.ontap.na_ontap_volume: |
| 86 | + state: present |
| 87 | + name: "{{ volume_name }}" |
| 88 | + size: "{{ volume_size }}" |
| 89 | + vserver: "{{ vserver }}" |
| 90 | + aggregate_name: "{{ aggr }}" |
| 91 | + junction_path: "{{ junction_path }}" |
| 92 | + volume_security_style: "{{ security_style }}" |
| 93 | + use_lambda: "{{ use_lambda }}" |
| 94 | + lambda_config: |
| 95 | + aws_profile: "{{ aws_profile }}" |
| 96 | + aws_region: "{{ aws_region }}" |
| 97 | + function_name: "{{ lambda_function_name }}" |
| 98 | + type: "{{ volume_type }}" |
| 99 | + size_unit: "mb" |
| 100 | + hostname: "{{ fsxn_hostname }}" |
| 101 | + username: "{{ username }}" |
| 102 | + password: "{{ password }}" |
| 103 | + validate_certs: false |
| 104 | + |
| 105 | + - name: Create CIFS Share |
| 106 | + netapp.ontap.na_ontap_cifs: |
| 107 | + state: present |
| 108 | + name: "{{ share_name }}" |
| 109 | + path: "{{ junction_path }}" |
| 110 | + vserver: "{{ vserver }}" |
| 111 | + use_lambda: "{{ use_lambda }}" |
| 112 | + lambda_config: |
| 113 | + aws_profile: "{{ aws_profile }}" |
| 114 | + aws_region: "{{ aws_region }}" |
| 115 | + function_name: "{{ lambda_function_name }}" |
| 116 | + hostname: "{{ fsxn_hostname }}" |
| 117 | + username: "{{ username }}" |
| 118 | + password: "{{ password }}" |
| 119 | + validate_certs: false |
0 commit comments