├── Readme.md └── ovh /Readme.md: -------------------------------------------------------------------------------- 1 | # Ansible OVH 2 | 3 | This is a small ansible wrapper around the ovh api. 4 | It is very lightweight but generic and should give you the possibility to use the full api of ovh and its fellow brands like kimsufi, soyoustart and runabove. 5 | Requires pyhton ovh client. Install with: 6 | 7 | pip install ovh 8 | 9 | 10 | ## Example Usage 11 | 12 | - name: get servers 13 | ovh: 14 | method: get 15 | endpoint: kimsufi-eu 16 | application_key: < application_key > 17 | application_secret: < application secret > 18 | consumer_key: < consumer key > 19 | uri: /dedicated/server 20 | 21 | - name: set rescue boot 22 | ovh: 23 | method: put 24 | endpoint: kimsufi-eu 25 | application_key: < application_key > 26 | application_secret: < application secret > 27 | consumer_key: < consumer key > 28 | uri: /dedicated/server/< server name > 29 | args: 30 | bootId: 22 31 | -------------------------------------------------------------------------------- /ovh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2015 Cornelius Keller 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | DOCUMENTATION = ''' 17 | --- 18 | module: ovh 19 | short_description: Ansible module to access ovh, kimsufi, soyoustart and runabove apis 20 | options: 21 | endpoint: 22 | - The ovh api endpoint. Must be one of 'ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca', 'runabove-ca'. 23 | application_key: 24 | - Your ovh api application_key 25 | application_secret: 26 | - Your ovh api application_secret 27 | consumer_key: 28 | - Your ovh api consumer_key 29 | method: 30 | - The request method 31 | uri: 32 | - The uri to call 33 | args: 34 | - the args for post or put requests 35 | author: 36 | - Cornelius Keller 37 | notes: 38 | - Requires python ovh api. Install with pip install ovh 39 | ''' 40 | 41 | EXAMPLES = ''' 42 | - name: get servers 43 | ovh: 44 | method: get 45 | endpoint: kimsufi-eu 46 | application_key: < application_key > 47 | application_secret: < application secret > 48 | consumer_key: < consumer key > 49 | uri: /dedicated/server 50 | 51 | - name: set rescue boot 52 | ovh: 53 | method: put 54 | endpoint: kimsufi-eu 55 | application_key: < application_key > 56 | application_secret: < application secret > 57 | consumer_key: < consumer key > 58 | uri: /dedicated/server/< server name > 59 | args: 60 | bootId: 22 61 | 62 | ''' 63 | 64 | 65 | from ansible.module_utils.basic import * 66 | 67 | 68 | module = AnsibleModule( 69 | argument_spec = dict( 70 | endpoint = dict(required=True, choices=['ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca', 'runabove-ca']), 71 | application_key = dict(required=True), 72 | application_secret = dict(required=True), 73 | consumer_key = dict(required=True), 74 | method = dict(required=True, choices=['get','put','post','delete']), 75 | uri = dict(required=True), 76 | args = dict(default={}, type='dict') 77 | ) 78 | ) 79 | 80 | from ovh import Client 81 | 82 | def main(): 83 | client = Client(endpoint=module.params['endpoint'], application_key=module.params['application_key'], application_secret=module.params['application_secret'], consumer_key=module.params['consumer_key']) 84 | method = getattr(client, module.params['method']) 85 | 86 | if module.params['args'] == {}: 87 | res = method(module.params['uri']) # module.params['args']) 88 | else: 89 | res = method(module.params['uri'], **module.params['args']) 90 | 91 | module.exit_json(changed=True, result=res) 92 | 93 | if __name__ == '__main__': 94 | main() 95 | --------------------------------------------------------------------------------