コード例 #1
0
def main():
    argument_spec = InfluxDb.influxdb_argument_spec()
    argument_spec.update(database_name=dict(required=True, type='str'),
                         state=dict(default='present',
                                    type='str',
                                    choices=['present', 'absent']))
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    state = module.params['state']

    influxdb = InfluxDb(module)
    client = influxdb.connect_to_influxdb()
    database_name = influxdb.database_name
    database = find_database(module, client, database_name)

    if state == 'present':
        if database:
            module.exit_json(changed=False)
        else:
            create_database(module, client, database_name)

    if state == 'absent':
        if database:
            drop_database(module, client, database_name)
        else:
            module.exit_json(changed=False)
コード例 #2
0
def main():
    argument_spec = InfluxDb.influxdb_argument_spec()
    argument_spec.update(database_name=dict(required=True, type='str'),
                         policy_name=dict(required=True, type='str'),
                         duration=dict(required=True, type='str'),
                         replication=dict(required=True, type='int'),
                         default=dict(default=False, type='bool'))
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    influxdb = InfluxDb(module)
    client = influxdb.connect_to_influxdb()

    retention_policy = find_retention_policy(module, client)

    if retention_policy:
        alter_retention_policy(module, client, retention_policy)
    else:
        create_retention_policy(module, client)
コード例 #3
0
def main():
    argument_spec = InfluxDb.influxdb_argument_spec()
    argument_spec.update(
        data_points=dict(required=True, type='list', elements='dict'),
        database_name=dict(required=True, type='str'),
    )
    module = AnsibleModule(argument_spec=argument_spec, )

    influx = AnsibleInfluxDBWrite(module)
    data_points = module.params.get('data_points')
    influx.write_data_point(data_points)
    module.exit_json(changed=True)
コード例 #4
0
def main():
    argument_spec = InfluxDb.influxdb_argument_spec()
    argument_spec.update(
        query=dict(type='str', required=True),
        database_name=dict(required=True, type='str'),
    )
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    influx = AnsibleInfluxDBRead(module)
    query = module.params.get('query')
    results = influx.read_by_query(query)
    module.exit_json(changed=True, query_results=results)
コード例 #5
0
def main():
    argument_spec = InfluxDb.influxdb_argument_spec()
    argument_spec.update(
        state=dict(default='present', type='str', choices=['present', 'absent']),
        database_name=dict(required=True, type='str'),
        policy_name=dict(required=True, type='str'),
        duration=dict(type='str'),
        replication=dict(type='int'),
        default=dict(default=False, type='bool'),
        shard_group_duration=dict(type='str'),
    )
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=(
            ('state', 'present', ['duration', 'replication']),
        ),
    )

    state = module.params['state']

    influxdb = InfluxDb(module)
    client = influxdb.connect_to_influxdb()

    retention_policy = find_retention_policy(module, client)

    if state == 'present':
        if retention_policy:
            alter_retention_policy(module, client, retention_policy)
        else:
            create_retention_policy(module, client)

    if state == 'absent':
        if retention_policy:
            drop_retention_policy(module, client)
        else:
            module.exit_json(changed=False)