From f8b081fa42bd0837950281b5f6b325e8c3a31a9a Mon Sep 17 00:00:00 2001 From: Brett Dellandre Date: Fri, 30 Dec 2022 11:06:15 -0500 Subject: [PATCH] initial commit --- .DS_Store | Bin 0 -> 6148 bytes README.md | 30 ++++ ansible.cfg | 6 + host_vars/sales-devvm-brett-dellandre.yml | 209 ++++++++++++++++++++++ hosts | 4 + initial.yml | 10 ++ roles/protectedpath/tasks/main.yml | 76 ++++++++ roles/protectionpolicies/tasks/main.yml | 91 ++++++++++ roles/quotas/tasks/main.yml | 79 ++++++++ roles/viewpolicies/tasks/main.yml | 144 +++++++++++++++ roles/views/tasks/main.yml | 89 +++++++++ secrets.yml | 7 + 12 files changed, 745 insertions(+) create mode 100644 .DS_Store create mode 100644 README.md create mode 100644 ansible.cfg create mode 100644 host_vars/sales-devvm-brett-dellandre.yml create mode 100644 hosts create mode 100644 initial.yml create mode 100644 roles/protectedpath/tasks/main.yml create mode 100644 roles/protectionpolicies/tasks/main.yml create mode 100644 roles/quotas/tasks/main.yml create mode 100644 roles/viewpolicies/tasks/main.yml create mode 100644 roles/views/tasks/main.yml create mode 100644 secrets.yml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 with the name of your VAST Data Cluster, this is case-sensitive. +### If you are using an Ansible Host instead of locally installed Ansible software, please indicate the IP adress to that Anisble host. +sales-devvm-brett-dellandre ansible_host=127.0.0.1 diff --git a/initial.yml b/initial.yml new file mode 100644 index 0000000..cadcd67 --- /dev/null +++ b/initial.yml @@ -0,0 +1,10 @@ +- hosts: all + gather_facts: no + vars_files: + - secrets.yml + roles: + - {name: viewpolicies, tags: [setup-viewpolicies]} + - {name: views, tags: [setup-views]} + - {name: quotas, tags: [setup-quotas]} + - {name: protectionpolicies, tags: [setup-protectionpolicies]} + - {name: protectedpath, tags: [setup-protectedpath]} \ No newline at end of file diff --git a/roles/protectedpath/tasks/main.yml b/roles/protectedpath/tasks/main.yml new file mode 100644 index 0000000..43ecf57 --- /dev/null +++ b/roles/protectedpath/tasks/main.yml @@ -0,0 +1,76 @@ +--- +- name: Find ID of Protection Policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectionpolicies/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: protectpolicyfind + +- name: Set up Protected Path + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectedpaths/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + name: "{{ item.name }}" + source_dir: "{{ item.source_dir }}" + protection_policy_id: "{{ protectpolicyfind.json | json_query(jmesquerypp) }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method == "POST" + register: protectedpathcreate + ignore_errors: true + vars: + jmesquerypp: "[? name=='{{ item.protection_policy_name }}'].id | [0]" + changed_when: protectedpathcreate.status != 409 + failed_when: protectedpathcreate.status == 400 + loop: "{{ protectedpaths }}" + +- name: Find ID of Protected Path + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectedpaths/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: protectedpathfind + +- name: Edit Protected Path + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectedpaths/{{ protectedpathfind.json | json_query(jmesquerypa) }}/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200, 204 + body: + name: "{{ item.name }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method != "POST" + register: protectedpathedit + ignore_errors: true + vars: + jmesquerypa: "[? name=='{{ item.name }}'].id | [0]" + changed_when: protectedpathedit.status != 409 + failed_when: protectedpathedit.status == 400 + loop: "{{ protectedpaths }}" diff --git a/roles/protectionpolicies/tasks/main.yml b/roles/protectionpolicies/tasks/main.yml new file mode 100644 index 0000000..704c3de --- /dev/null +++ b/roles/protectionpolicies/tasks/main.yml @@ -0,0 +1,91 @@ +--- +- name: Gather Time Facts + setup: + gather_subset: + - 'date_time' + delegate_to: localhost + +- name: Set up Protection Policies + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectionpolicies/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + name: "{{ item.name }}" + frames: + - + every: "{{ item.every_value }}{{ item.every_unit }}" + every_value: "{{ item.every_value }}" + every_unit: "{{ item.every_unit }}" + start-at: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}" + keep-local: "{{ item.keep_local_value }}{{ item.keep_local_period }}" + keep-remote: "{{ item.keep_remote | default(omit) }}" + local-period: "{{ item.keep_local_period }}" + prefix: "{{ item.snapshot_prefix }}" + clone_type: "{{ item.clone_type|upper }}" + target_object_id: "{{ item.replication_target | default(omit) }}" + indestructible: "{{ item.indestructible }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method == "POST" + register: protectionpolicycreate + ignore_errors: true + changed_when: protectionpolicycreate.status != 409 + failed_when: protectionpolicycreate.status == 400 + loop: "{{ protectionpolicies }}" + +- name: Find ID of Protection Policy + block: + - name: Get ID of Protection Policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectionpolicies/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: protectionpolicyfind + +- name: Edit Protection Policies + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/protectionpolicies/{{ protectionpolicyfind.json | json_query(jmesquerypp) }}/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + name: "{{ item.name }}" + frames: + - + every: "{{ item.every_value }}{{ item.every_unit }}" + every_value: "{{ item.every_value }}" + every_unit: "{{ item.every_unit }}" + keep-local: "{{ item.keep_local_value }}{{ item.keep_local_period }}" + keep-remote: "{{ item.keep_remote | default(omit) }}" + local-period: "{{ item.keep_local_period }}" + prefix: "{{ item.snapshot_prefix }}" + clone_type: "{{ item.clone_type|upper }}" + target_object_id: "{{ item.replication_target | default(omit) }}" + indestructible: "{{ item.indestructible }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method != "POST" + register: protectionpolicyedit + ignore_errors: true + vars: + jmesquerypp: "[? name=='{{ item.name }}'].id | [0]" + changed_when: protectionpolicyedit.status != 409 + failed_when: protectionpolicyedit.status == 400 + loop: "{{ protectionpolicies }}" diff --git a/roles/quotas/tasks/main.yml b/roles/quotas/tasks/main.yml new file mode 100644 index 0000000..0ae90e2 --- /dev/null +++ b/roles/quotas/tasks/main.yml @@ -0,0 +1,79 @@ +--- +- name: Set up Quota + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/quotas/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + name: "{{ item.name }}" + path: "{{ item.path }}" + soft_limit: "{{ item.soft_limit_capacity | human_to_bytes }}" + hard_limit: "{{ item.hard_limit_capacity | human_to_bytes }}" + soft_limit_inodes: "{{ item.soft_limit_folders }}" + hard_limit_inodes: "{{ item.hard_limit_folders }}" + enable_alarms: "{{ item.enable_alarms }}" + grace_period: "{{ item.grace_period }}" + enable_email_providers: "{{ item.enable_email_providers }}" + create_dir: "{{ item.create_dir }}" + is_user_quota: "{{ item.is_user_quota}}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method == "POST" + register: quotacreate + ignore_errors: true + changed_when: quotacreate.status != 409 + failed_when: quotacreate.status == 400 + loop: "{{ quotas }}" + +- name: Find ID of Quota Policy + block: + - name: Get ID of Quota Policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/quotas/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: quotasfind + +- name: Edit Quota + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/quotas/{{ quotasfind.json | json_query(jmesqueryq) }}/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200, 204 + body: + name: "{{ item.name }}" + path: "{{ item.path }}" + soft_limit: "{{ item.soft_limit_capacity | human_to_bytes }}" + hard_limit: "{{ item.hard_limit_capacity | human_to_bytes }}" + soft_limit_inodes: "{{ item.soft_limit_folders }}" + hard_limit_inodes: "{{ item.hard_limit_folders }}" + enable_alarms: "{{ item.enable_alarms }}" + grace_period: "{{ item.grace_period }}" + enable_email_providers: "{{ item.enable_email_providers }}" + create_dir: "{{ item.create_dir }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method != "POST" + register: quotaedit + ignore_errors: true + vars: + jmesqueryq: "[? name=='{{ item.name }}'].id | [0]" + changed_when: quotaedit.status != 409 + failed_when: quotaedit.status == 400 + loop: "{{ quotas }}" diff --git a/roles/viewpolicies/tasks/main.yml b/roles/viewpolicies/tasks/main.yml new file mode 100644 index 0000000..f99614b --- /dev/null +++ b/roles/viewpolicies/tasks/main.yml @@ -0,0 +1,144 @@ +--- +- name: Find ID of VIP Pool + block: + - name: Get ID of VIP Pool + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/vippools/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: vippoolfind + +- name: Set up view policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/viewpolicies/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + name: "{{ item.name }}" + flavor: "{{ item.flavor }}" + # vip_pools: ["{{ vippoolfind.json | json_query(jmesquery) }}"] + use_auth_provider: "{{ item.use_auth_provider | default(omit) }}" + nfs_posix_acl: "{{ item.nfs_posix_acl | default(omit) }}" + auth_source: "{{ item.auth_source }}" + path_length: "{{ item.path_length | default(omit) }}" + allowed_characters: "{{ item.allowed_characters | default(omit) }}" + nfs_no_squash: "{{ item.nfs_no_squash | default(omit) }}" + nfs_root_squash: "{{ item.nfs_root_squash | default(omit) }}" + nfs_all_squash: "{{ item.nfs_all_squash | default(omit) }}" + trash_access: "{{ item.trash_access | default(omit) }}" + read_write: "{{ item.nfs_read_write | default(omit) }}" + read_only: "{{ item.nfs_read_only | default(omit) }}" + smb_read_write: "{{ item.smb_read_write | default(omit) }}" + smb_read_only: "{{ item.smb_read_only | default(omit) }}" + s3_read_write: "{{ item.s3_read_write | default(omit) }}" + s3_read_only: "{{ item.s3_read_only | default(omit) }}" + s3_visibility: "{{ item.s3_visibility | default(omit) }}" + s3_visibility_groups: "{{ item.s3_visibility_groups | default(omit) }}" + apple_sid: "{{ item.apple_sid | default(omit) }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method == "POST" + register: viewpolicycreate + ignore_errors: true + # vars: + # jmesquery: "[? name=='{{ item.vip_pool_name }}'].id | [0] || []]" + changed_when: viewpolicycreate.status != 409 + failed_when: viewpolicycreate.status == 400 + loop: "{{ viewpolicies }}" + +- name: Find ID of View Policy + block: + - name: Get ID of View Policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/viewpolicies/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: viewpolicyfind + +- name: Edit viewpolicy with VIPPOOL + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/viewpolicies/{{ viewpolicyfind.json | json_query(jmesqueryvp) }}/' + return_content: true + method: "PATCH" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200, 201, 203, 204, 301 + body: + vip_pools: ["{{ vippoolfind.json | json_query(jmesquery) }}"] + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + # when: item.vip_pool_name | length == 1 and item.method == "POST" + register: viewpolicycreatevip + ignore_errors: true + vars: + jmesquery: "[? name=='{{ item.vip_pool_name }}'].id | [0]" + jmesqueryvp: "[? name=='{{ item.name }}'].id | [0]" + changed_when: viewpolicycreatevip.status != 409 + failed_when: viewpolicycreatevip.status == 400 + when: item.vip_pool_name is defined and item.vip_pool_name != '' and item.method == 'POST' + loop: "{{ viewpolicies }}" + +- name: Edit viewpolicy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/viewpolicies/{{ viewpolicyfind.json | json_query(jmesqueryvp) }}/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200, 201, 203, 204, 301 + body: + name: "{{ item.name }}" + flavor: "{{ item.flavor }}" + # vip_pools: ["{{ vippoolfind.json | json_query(jmesquery) }}"] + use_auth_provider: "{{ item.use_auth_provider | default(omit) }}" + nfs_posix_acl: "{{ item.nfs_posix_acl | default(omit) }}" + auth_source: "{{ item.auth_source }}" + path_length: "{{ item.path_length | default(omit) }}" + allowed_characters: "{{ item.allowed_characters | default(omit) }}" + nfs_no_squash: "{{ item.nfs_no_squash | default(omit) }}" + nfs_root_squash: "{{ item.nfs_root_squash | default(omit) }}" + nfs_all_squash: "{{ item.nfs_all_squash | default(omit) }}" + trash_access: "{{ item.trash_access | default(omit) }}" + read_write: "{{ item.nfs_read_write | default(omit) }}" + read_only: "{{ item.nfs_read_only | default(omit) }}" + smb_read_write: "{{ item.smb_read_write | default(omit) }}" + smb_read_only: "{{ item.smb_read_only | default(omit) }}" + s3_read_write: "{{ item.s3_read_write | default(omit) }}" + s3_read_only: "{{ item.s3_read_only | default(omit) }}" + s3_visibility: "{{ item.s3_visibility | default(omit) }}" + s3_visibility_groups: "{{ item.s3_visibility_groups | default(omit) }}" + apple_sid: "{{ item.apple_sid | default(omit) }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method != "POST" + register: viewpolicyedit + ignore_errors: true + vars: + # jmesquery: "[? name=='{{ item.vip_pool_name }}'].id | [0]" + jmesqueryvp: "[? name=='{{ item.name }}'].id | [0]" + changed_when: viewpolicyedit.status != 409 + failed_when: viewpolicyedit.status == 400 + loop: "{{ viewpolicies }}" diff --git a/roles/views/tasks/main.yml b/roles/views/tasks/main.yml new file mode 100644 index 0000000..56e8859 --- /dev/null +++ b/roles/views/tasks/main.yml @@ -0,0 +1,89 @@ +--- +- name: Find ID of View Policy + block: + - name: Find ID of View Policy + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/viewpolicies/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: viewpolicyfind + +- name: Set up views + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/views/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 201, 200 + body: + path: "{{ item.path }}" + policy_id: "{{ viewpolicyfind.json | json_query(jmesquery) }}" + alias: "{{ item.alias | default(omit) }}" + protocols: "{{ item.protocols.split(',') }}" + create_dir: "{{ item.create_dir }}" + share: "{{ item.share | default(omit) }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method == "POST" + register: viewscreate + ignore_errors: true + vars: + jmesquery: "[? name=='{{ item.view_policy_name }}'].id | [0]" + changed_when: viewscreate.status != 409 + failed_when: viewscreate.status == 400 + loop: "{{ views }}" + +- name: Find ID of View + block: + - name: Get ID of View + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/views/' + return_content: false + method: GET + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200 + force_basic_auth: yes + validate_certs: false + body_format: json + delegate_to: localhost + register: viewfind + +- name: Edit views + ansible.builtin.uri: + url: 'https://{{ vms_ip }}/api/views/{{ viewfind.json | json_query(jmesquery) }}/' + return_content: true + method: "{{ item.method }}" + user: "{{ vast_user }}" + password: "{{ vast_pass }}" + status_code: 200, 201, 203, 204, 301 + body: + path: "{{ item.path }}" + policy_id: ["{{ viewpolicyfind.json | json_query(jmesqueryvp) }}"] + alias: "{{ item.alias | default(omit) }}" + protocols: "{{ item.protocols.split(',') }}" + create_dir: "{{ item.create_dir }}" + share: "{{ item.share | default(omit) }}" + body_format: json + force_basic_auth: yes + validate_certs: false + delegate_to: localhost + when: item.method != "POST" + register: viewsedit + ignore_errors: true + vars: + jmesquery: "[? path=='{{ item.path }}'].id | [0]" + jmesqueryvp: "[? name=='{{ item.view_policy_name }}'].id | [0]" + changed_when: viewsedit.status != 409 + failed_when: viewsedit.status == 400 + loop: "{{ views }}" diff --git a/secrets.yml b/secrets.yml new file mode 100644 index 0000000..af736ab --- /dev/null +++ b/secrets.yml @@ -0,0 +1,7 @@ +$ANSIBLE_VAULT;1.1;AES256 +64326239663361376530373132336430306532393135353933356434343066666365643435323230 +3164656136633430383562643537376530373161383166330a393939366166393236316435656438 +64623337653432313136316232356362343061303862353965666633646634383666626431363836 +3536623066663763320a646463363566303935326535376165653963383566393562616238343266 +61626663346636303061633064393436383731663862303966653931643533386137626463656233 +3764613832646663633163353931353735623539653935643130