Setup the icinga2 node.

    name
        The domain name for which this certificate will be saved

    master
        Icinga2 master node for which this certificate will be saved

    ticket
        Authentication ticket generated on icinga2 master

def node_setup(name, master, ticket):
    '''
    Setup the icinga2 node.

    name
        The domain name for which this certificate will be saved

    master
        Icinga2 master node for which this certificate will be saved

    ticket
        Authentication ticket generated on icinga2 master
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}
    cert = "{0}{1}.crt.orig".format(get_certs_path(), name)
    key = "{0}{1}.key.orig".format(get_certs_path(), name)

    # Checking if execution is needed.
    if os.path.isfile(cert) and os.path.isfile(cert):
        ret['comment'] = 'No execution needed. Node already configured.'
        return ret
    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'Node setup will be executed.'
        return ret

    # Executing the command.
    node_setup = __salt__['icinga2.node_setup'](name, master, ticket)
    if not node_setup['retcode']:
        ret['comment'] = "Node setup executed."
        ret['changes']['cert'] = "Node setup finished successfully."
        return ret

    ret['comment'] = "FAILED. Node setup failed with outpu: {0}".format(node_setup['stdout'])
    ret['result'] = False
    return ret