def generate_cert(name):
 ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
 cert = '/etc/icinga2/pki/{0}.crt'.format(name)
 key = '/etc/icinga2/pki/{0}.key'.format(name)
 if (os.path.isfile(cert) and os.path.isfile(key)):
  ret['comment'] = 'No execution needed. Cert: {0} and key: {1} already generated.'.format(cert, key)
  return ret
 if __opts__['test']:
  ret['result'] = None
  ret['comment'] = 'Certificate and key generation would be executed'
  return ret
 cert_save = __salt__['icinga2.generate_cert'](name)
 if (not cert_save):
  ret['comment'] = 'Certificate and key generated'
  ret['changes']['cert'] = 'Executed. Certificate saved: {0}'.format(cert)
  ret['changes']['key'] = 'Executed. Key saved: {0}'.format(key)
 return ret

def generate_cert ( name ) : ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : '' } cert = '/etc/icinga2/pki/{0}.crt' . format ( name ) key = '/etc/icinga2/pki/{0}.key' . format ( name ) if ( os . path . isfile ( cert ) and os . path . isfile ( key ) ) : ret [ 'comment' ] = 'No execution needed. Cert: {0} and key: {1} already generated.' . format ( cert , key ) return ret if __opts__ [ 'test' ] : ret [ 'result' ] = None ret [ 'comment' ] = 'Certificate and key generation would be executed' return ret cert_save = __salt__ [ 'icinga2.generate_cert' ] ( name ) if ( not cert_save ) : ret [ 'comment' ] = 'Certificate and key generated' ret [ 'changes' ] [ 'cert' ] = 'Executed. Certificate saved: {0}' . format ( cert ) ret [ 'changes' ] [ 'key' ] = 'Executed. Key saved: {0}' . format ( key ) return ret
generate an icinga2 certificate and key on the client .