def main(): module = ForemanEntityAnsibleModule(argument_spec=dict( hostname=dict(required=True), state=dict(default='present', choices=['on', 'off', 'state']), ), ) (host_dict, state) = module.parse_params() module.connect() entity = find_host(module, host_dict['hostname'], failsafe=True) if state == 'state': power_state = query_power_state(module, entity) module.exit_json(changed=False, power_state=power_state) else: changed = naildown_power_state(module, entity, state) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), hostgroup=dict(), location=dict(), organization=dict(), enabled=dict(default='true', type='bool'), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), required_if=( ['state', 'present_with_defaults', ['hostgroup']], ['state', 'present', ['hostgroup']], ), supports_check_mode=True, ) (host_dict, state) = module.parse_params() module.connect() host_dict['hostgroup'] = find_hostgroup(module, host_dict['hostgroup'], failsafe=True) host_dict['name'] = host_dict['name'] + '.' + \ host_dict['hostgroup'].domain.read().fullname entity = find_host(module, host_dict['name'], failsafe=True) if 'location' in host_dict: host_dict['location'] = find_location(module, host_dict['location']) if 'organization' in host_dict: host_dict['organization'] = find_organization( module, host_dict['organization']) host_dict = sanitize_entity_dict(host_dict, name_map) changed = naildown_entity_state(Host, host_dict, entity, state, module) module.exit_json(changed=changed)