Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.1 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
DOCUMENTATION = '''
---
module: container_exists
author: Edoardo Putti
short_description: Check existance for container
description:
- Check if a container with the given name exists
options:
name:
required: true
description:
- Name of the container
'''
from ansible.module_utils.basic import *
def main():
module = AnsibleModule(
argument_spec=dict(
name= dict(
required= True,
type= 'str',
),
),
supports_check_mode=True
)
try:
import lxc
except ImportError:
self.module.fail_json(
changed= False,
msg= 'Error importing lxc, is python-lxc installed?',
)
container_name = module.params.get('name')
result = {}
result['name'] = container_name
if container_name in lxc.list_containers():
result['exists'] = True
else:
result['exists'] = False
result['changed'] = True
module.exit_json(**result)
if __name__ == '__main__':
main()