Ansible Playbook to backup NSX-T Segments
I thought a lot before I write this blog here. but as it is about the NSX , I will put it here.
I will not go into how to setup Ansible Tower. I assume that you have Ansible Tower and Versioning Control System in your environment.
Hereunder is the playbook that you can use. but I need to show you how you can encrypt your password.
- hosts: all
connection: local
gather_facts: false
vars:
host:
devNsx:
- https://FirstNSX.xyz.com/policy/api/v1/infra
prodNsx:
- https://SecondNSX.xyz.com/policy/api/v1/infra/
urls:
- /segments
tasks:
- name: DEV NSX-T Test Calls
uri:
url: "{{ host.devNsx[0] }}{{ urls[0] }}"
force_basic_auth: yes
validate_certs: no
headers:
Accept: "application/json"
Content-Type: "application/json"
user: admin
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
66326538633731666237666536306338656131616564376261393965633934386536363463386463
method: GET
status_code: "200"
body_format: json
register: response
- debug: var=response.json
Here how I encrypted the password
root@AnsibleServerCli:~/ansible# ansible-vault encrypt_string 'MyPassword' --name 'password'
New Vault password:
Confirm New Vault password:
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
66326538633731666237666536306338656131616564376261393965633934386536363463386463
Encryption successful
This website can do it for you https://ansible-vault-tool.com/ . but I don't recommend to do so.
I created a credential with type vault and I used it in the AWX template
ansible-playbook YOURPLAYBOOKNAME --vault-id @prompt
No comments:
Post a Comment