|
|
|
@ -7,63 +7,56 @@
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
|
'status': ['preview'],
|
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
|
---
|
|
|
|
|
module: atomic_image
|
|
|
|
|
short_description: Manage the container images on the atomic host platform
|
|
|
|
|
description:
|
|
|
|
|
- Manage the container images on the atomic host platform
|
|
|
|
|
- Allows to execute the commands specified by the RUN label in the container image when present
|
|
|
|
|
- Manage the container images on the atomic host platform.
|
|
|
|
|
- Allows to execute the commands specified by the RUN label in the container image when present.
|
|
|
|
|
version_added: "2.2"
|
|
|
|
|
author: "Saravanan KR @krsacme"
|
|
|
|
|
author:
|
|
|
|
|
- Saravanan KR (@krsacme)
|
|
|
|
|
notes:
|
|
|
|
|
- Host should support C(atomic) command
|
|
|
|
|
- Host should support C(atomic) command.
|
|
|
|
|
requirements:
|
|
|
|
|
- atomic
|
|
|
|
|
- "python >= 2.6"
|
|
|
|
|
- python >= 2.6
|
|
|
|
|
options:
|
|
|
|
|
backend:
|
|
|
|
|
description:
|
|
|
|
|
- Define the backend where the image is pulled.
|
|
|
|
|
required: False
|
|
|
|
|
choices: ["docker", "ostree"]
|
|
|
|
|
default: None
|
|
|
|
|
choices: [ docker, ostree ]
|
|
|
|
|
version_added: "2.4"
|
|
|
|
|
name:
|
|
|
|
|
description:
|
|
|
|
|
- Name of the container image
|
|
|
|
|
- Name of the container image.
|
|
|
|
|
required: True
|
|
|
|
|
default: null
|
|
|
|
|
state:
|
|
|
|
|
description:
|
|
|
|
|
- The state of the container image.
|
|
|
|
|
- The state C(latest) will ensure container image is upgraded to the latest version and forcefully restart container, if running.
|
|
|
|
|
required: False
|
|
|
|
|
choices: ["present", "absent", "latest"]
|
|
|
|
|
choices: [ absent, latest, present ]
|
|
|
|
|
default: latest
|
|
|
|
|
started:
|
|
|
|
|
description:
|
|
|
|
|
- Start or Stop the container
|
|
|
|
|
required: False
|
|
|
|
|
choices: ["yes", "no"]
|
|
|
|
|
default: yes
|
|
|
|
|
- Start or Stop the container.
|
|
|
|
|
type: bool
|
|
|
|
|
default: 'yes'
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
|
|
|
|
|
|
# Execute the run command on rsyslog container image (atomic run rhel7/rsyslog)
|
|
|
|
|
- atomic_image:
|
|
|
|
|
- name: Execute the run command on rsyslog container image (atomic run rhel7/rsyslog)
|
|
|
|
|
atomic_image:
|
|
|
|
|
name: rhel7/rsyslog
|
|
|
|
|
state: latest
|
|
|
|
|
|
|
|
|
|
# Pull busybox to the OSTree backend
|
|
|
|
|
- atomic_image:
|
|
|
|
|
- name: Pull busybox to the OSTree backend
|
|
|
|
|
atomic_image:
|
|
|
|
|
name: busybox
|
|
|
|
|
state: latest
|
|
|
|
|
backend: ostree
|
|
|
|
@ -85,7 +78,7 @@ from ansible.module_utils._text import to_native
|
|
|
|
|
def do_upgrade(module, image):
|
|
|
|
|
args = ['atomic', 'update', '--force', image]
|
|
|
|
|
rc, out, err = module.run_command(args, check_rc=False)
|
|
|
|
|
if rc != 0: # something went wrong emit the msg
|
|
|
|
|
if rc != 0: # something went wrong emit the msg
|
|
|
|
|
module.fail_json(rc=rc, msg=err)
|
|
|
|
|
elif 'Image is up to date' in out:
|
|
|
|
|
return False
|
|
|
|
@ -122,7 +115,7 @@ def core(module):
|
|
|
|
|
changed = "Extracting" in out or "Copying blob" in out
|
|
|
|
|
module.exit_json(msg=(out + out_run), changed=changed)
|
|
|
|
|
elif state == 'absent':
|
|
|
|
|
args = ['atomic', 'images', 'delete', "--storage=%s" % backend, image]
|
|
|
|
|
args = ['atomic', 'images', 'delete', "--storage=%s" % backend, image]
|
|
|
|
|
if rc < 0:
|
|
|
|
|
module.fail_json(rc=rc, msg=err)
|
|
|
|
|
else:
|
|
|
|
@ -156,12 +149,12 @@ def core(module):
|
|
|
|
|
def main():
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
|
argument_spec=dict(
|
|
|
|
|
backend=dict(default=None, choices=['docker', 'ostree']),
|
|
|
|
|
name=dict(default=None, required=True),
|
|
|
|
|
state=dict(default='latest', choices=['present', 'absent', 'latest']),
|
|
|
|
|
started=dict(default='yes', type='bool'),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
backend=dict(type='str', choices=['docker', 'ostree']),
|
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
|
state=dict(type='str', default='latest', choices=['absent', 'latest', 'present']),
|
|
|
|
|
started=dict(type='bool', default=True),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Verify that the platform supports atomic command
|
|
|
|
|
rc, out, err = module.run_command('atomic -v', check_rc=False)
|
|
|
|
|