Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Last active August 29, 2016 17:01
Show Gist options
  • Save gnilchee/edb90e2b3ad731ce046a7744eab79d2f to your computer and use it in GitHub Desktop.
Save gnilchee/edb90e2b3ad731ce046a7744eab79d2f to your computer and use it in GitHub Desktop.
dictionary extraction practice
#!/usr/bin/env python3
env = {
'dev': {
'web_ext': {
'services': ['httpd', 'redis', 'tripwire'],
'servers': ['web1.ext.dev.domain.com', 'web2.ext.dev.domain.com'],
'type': 'ssh',
},
'web_int': {
'services': ['httpd', 'redis'],
'servers': ['web.int.dev.domain.com'],
'type': 'ssh',
},
'db': {
'services': ['mariadb'],
'servers': ['db.dev.domain.com'],
'type': 'ssh',
},
},
'test': {
'web_ext': {
'services': ['httpd', 'redis', 'tripwire'],
'servers': ['web1.ext.tst.domain.com', 'web2.ext.tst.domain.com'],
'type': 'ssh',
},
'web_int': {
'services': ['httpd', 'redis'],
'servers': ['web.int.tst.domain.com'],
'type': 'ssh',
},
'db': {
'services': ['mariadb'],
'servers': ['db.tst.domain.com'],
'type': 'ssh',
},
},
'prod': {
'web_ext': {
'services': ['httpd', 'redis', 'tripwire'],
'servers': ['web1.ext.prd.domain.com', 'web2.ext.prd.domain.com'],
'type': 'ssh',
},
'web_int': {
'services': ['httpd', 'redis'],
'servers': ['web.int.prd.domain.com'],
'type': 'ssh',
},
'db': {
'services': ['mariadb'],
'servers': ['db.prd.domain.com'],
'type': 'ssh',
},
},
}
print("dev servers for database:", env['dev']['db']['servers'])
print("test servers for web internal server:", env['test']['web_int']['servers'])
print("prod servers for web external server:", env['prod']['web_ext']['servers'])
print("dev web external servers have the following service(s):", env['dev']['web_ext']['services'])
print("prod database servers have the following service(s):", env['prod']['db']['services'])
print("test web internal servers have the following services:", env['test']['web_int']['services'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment