Created
October 9, 2022 17:21
-
-
Save kayiwa/39835927587b82d0ee4f8c005ddcc40d to your computer and use it in GitHub Desktop.
digitalocean_mongodb_debug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# playbook with tasks to create mongodb on digital ocean | |
- name: deploy mongo on digital ocrean | |
hosts: localhost | |
connection: local | |
gather_facts: false | |
tasks: | |
- name: d_ocean | create mongodb database | |
ansible.builtin.command: doctl databases create db-demo --region sfo3 --engine mongodb --version 5 --output json | |
async: 1800 | |
poll: 60 | |
register: demo_database | |
- name: d_ocean | Print return information for db_url | |
ansible.builtin.debug: | |
var: demo_database.stdout | |
verbosity: 2 | |
- name: d_ocean | Display mongodb password url | |
ansible.builtin.debug: | |
msg: "{{ demo_database.stdout | community.general.json_query(uri_query) }}" | |
vars: | |
uri_query: "private_connection[?starts_with(host,'private-db-demo')].uri" | |
- name: d_ocean | Print return information for db_url | |
ansible.builtin.debug: | |
var: "{{ demo_database.stdout[private_connection | string ] }}" | |
verbosity: 2 | |
ignore_errors: true | |
- name: d_ocean | copy the database info doctl created | |
ansible.builtin.copy: | |
content: "{{ demo_database.stdout }}" | |
dest: "/tmp/{{ lookup('pipe', 'date +%Y-%m-%d@$H:%M:%S') }}d_ocean_mongodb.txt" | |
delegate_to: localhost | |
ignore_errors: true | |
# playbook output | |
❯ ansible-playbook -vv playbooks/db_debug.yml | |
ansible-playbook [core 2.13.2] | |
config file = None | |
python version = 3.10.6 (main, Aug 13 2022, 11:37:32) [Clang 13.1.6 (clang-1316.0.21.2.5)] | |
jinja version = 3.1.2 | |
libyaml = True | |
No config file found; using defaults | |
__________________________________________ | |
< TASK [d_ocean | create mongodb database] > | |
------------------------------------------ | |
ASYNC OK on localhost: jid=876796620544.50632 | |
changed: [localhost] => {"ansible_job_id": "876796620544.50632", "changed": true, "cmd": ["doctl", "databases", "create", "db-demo", "--region", "sfo3", "--engine", "mongodb", "--version", "5", "--output", "json"], "delta": } | |
______________________________________________________ | |
< TASK [d_ocean | Print return information for db_url] > | |
------------------------------------------------------ | |
ok: [localhost] => { | |
"demo_database.stdout": [ | |
{ | |
"connection": { | |
"database": "admin", | |
"host": "db-demo-xxxxxxxx.mongo.ondigitalocean.com", | |
"password": "XXXXXXXXXXXXXXXX", | |
"port": 27017, | |
"ssl": true, | |
"uri": "mongodb+srv://doadmin:XXXXXXXXXXXXXXXX@db-demo-xxxxxxxx.mongo.ondigitalocean.com/admin?tls=true&authSource=admin", | |
"user": "doadmin" | |
}, | |
"created_at": "2022-10-09T15:56:48Z", | |
"engine": "mongodb", | |
"id": "599a8a7d-b388-4897-b150-f8d36e3188b6", | |
"maintenance_window": {}, | |
"name": "db-demo", | |
"num_nodes": 1, | |
"private_connection": { | |
"database": "admin", | |
"host": "private-db-demo-xxxxxxxx.mongo.ondigitalocean.com", | |
"password": "XXXXXXXXXXXXXXXX", | |
"port": 27017, | |
"ssl": true, | |
"uri": "mongodb+srv://doadmin:XXXXXXXXXXXXXXXX@private-db-demo-xxxxxxxx.mongo.ondigitalocean.com/admin?tls=true&authSource=admin", | |
"user": "doadmin" | |
}, | |
"private_network_uuid": "2ff043e5-ad73-4c6f-a3c4-fea4f9a6736e", | |
"region": "sfo3", | |
"size": "db-s-1vcpu-1gb", | |
"status": "creating", | |
"version": "5" | |
} | |
] | |
} | |
_______________________________________________ | |
< TASK [d_ocean | Display mongodb password url] > | |
----------------------------------------------- | |
ok: [localhost] => { | |
"msg": "" | |
} | |
______________________________________________________ | |
< TASK [d_ocean | Print return information for db_url] > | |
------------------------------------------------------ | |
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'private_connection' is undefined\n\nThe error appears to be in '/Users/kayiwa/Documents/dev/webrecorder/browsertrix} | |
...ignoring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment