diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/connect_hostpool.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/connect_hostpool.yml new file mode 100644 index 00000000..43d63fc7 --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/connect_hostpool.yml @@ -0,0 +1,13 @@ +--- +- hosts: all + name: Connect to hostpool + become: true + + pre_tasks: + - name: Debug vars + debug: + msg: "{{ vars | to_json }}" + + roles: + - setup + - connect_hostpool diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/create_byon_location_resource.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/create_byon_location_resource.yml new file mode 100644 index 00000000..2073fcba --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/create_byon_location_resource.yml @@ -0,0 +1,13 @@ +--- +- hosts: all + name: Add BYON on-demand resource + become: true + + pre_tasks: + - name: Debug vars + debug: + msg: "{{ vars | to_json }}" + + roles: + - setup + - create_byon_location_resource diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/inputs.json.tpl b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/inputs.json.tpl new file mode 100644 index 00000000..63d7d30f --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/inputs.json.tpl @@ -0,0 +1,16 @@ +{ +"NODE": "Test", +"INSTANCE": "Test", +"SOURCE_NODE": "Test", +"SOURCE_INSTANCE": "Test", +"alien_url": "http://localhost:8088", +"alien_user": "admin", +"alien_password": "admin", +"cfy_url": "https://52.48.126.116:443", +"cfy_user": "admin", +"cfy_password": "ad1min", +"name": "CFYOrchestrator", +"pluginId": "alien-cloudify-4-orchestrator-premium", +"pluginBean": "cloudify-orchestrator", +"disableDiamondMonitorAgent": "true" +} diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/playbook.ansible b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/playbook.ansible new file mode 100644 index 00000000..430753a9 Binary files /dev/null and b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/playbook.ansible differ diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/connect_hostpool/tasks/main.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/connect_hostpool/tasks/main.yml new file mode 100644 index 00000000..f6ee60cf --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/connect_hostpool/tasks/main.yml @@ -0,0 +1,18 @@ +--- + +- set_fact: + file_path: "/tmp/a4cPlaybookRegistry/{{ SOURCE_NODE }}/{{ SOURCE_INSTANCE }}/connect_hostpool/inputs/hostpool_url" + when: hostpool_url is defined +- set_fact: + file_dir: "{{ file_path | dirname }}" + when: hostpool_url is defined + +- name: "Ensure directory <{{ file_dir }}> exists" + file: + path: "{{ file_dir }}" + state: directory + when: hostpool_url is defined + +- name: "Echo <{{ hostpool_url }}> into {{ file_path }}" + shell: "echo '{{ hostpool_url }}' > {{ file_path }}" + when: hostpool_url is defined diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/create_byon_location_resource/tasks/main.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/create_byon_location_resource/tasks/main.yml new file mode 100644 index 00000000..5a9fb8be --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/create_byon_location_resource/tasks/main.yml @@ -0,0 +1,72 @@ +--- + +# read hostpool_url from hostpool connection +- name: Check relationship inputs exists + stat: path="/tmp/a4cPlaybookRegistry/{{ NODE }}/{{ INSTANCE }}/connect_hostpool/inputs/hostpool_url" + register: hostpool_url_file +- name: read relationship inputs + command: /bin/cat "/tmp/a4cPlaybookRegistry/{{ NODE }}/{{ INSTANCE }}/connect_hostpool/inputs/hostpool_url" + register: hostpool_url_content + when: hostpool_url_file.stat.exists +- set_fact: + hostpool_url: "{{ hostpool_url_content.stdout_lines[0] }}" + when: hostpool_url_file.stat.exists and hostpool_url_content.stdout_lines|length > 0 + +- name: login + uri: + url: "{{ alien_url }}/login?username={{ alien_user }}&password={{ alien_password }}&submit=Login" + method: POST + return_content: yes + status_code: 302 + headers: + Content-Type: "application/x-www-form-urlencoded" + register: login + +- set_fact: + session_id: "{{ login.set_cookie.split(';')[0] }}" + +- name: Create on-demand location resource + uri: + url: "{{ alien_url }}/rest/latest/orchestrators/{{ orchestratorId }}/locations/{{ locationId }}/resources" + method: POST + return_content: yes + HEADER_cookie: "{{ session_id }}" + body: + resourceType: "{{ resourceType }}" + resourceName: "{{ resourceName }}" + archiveName: "{{ resourceArchiveName }}" + archiveVersion: "{{ resourceArchiveVersion }}" + id: "{{ resourceType }}:{{ resourceArchiveVersion }}" + body_format: json + status_code: 200 + register: result + +- set_fact: + resourceId: "{{ result.json.data.resourceTemplate.id }}" + +- name: Configure on-demand location resource + uri: + url: "{{ alien_url }}/rest/latest/orchestrators/{{ orchestratorId }}/locations/{{ locationId }}/resources/{{ resourceId }}/template/properties" + method: POST + return_content: yes + HEADER_cookie: "{{ session_id }}" + body: + propertyName: "host_pool_service_endpoint" + propertyValue: "{{ hostpool_url }}" + body_format: json + status_code: 200 + register: result + +- name: Configure on-demand location resource + uri: + url: "{{ alien_url }}/rest/latest/orchestrators/{{ orchestratorId }}/locations/{{ locationId }}/resources/{{ resourceId }}/template/properties" + method: POST + return_content: yes + HEADER_cookie: "{{ session_id }}" + body: + propertyName: "agent_config" + propertyValue: + install_method: "{{ resourceAgentInstallMethod }}" + body_format: json + status_code: 200 + register: result diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/setup/tasks/main.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/setup/tasks/main.yml new file mode 100644 index 00000000..0109dc75 --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/playbook/roles/setup/tasks/main.yml @@ -0,0 +1,52 @@ +- name: Add repository + yum: + name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + state: present + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat' + +# Install system dependencies (Centos Redhat) +- name: Install system dependencies + yum: pkg={{ item }} state=present + with_items: + - gcc + - python-devel + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat' + +# Install system dependencies (Ubuntu) +- name: Preprare apt cache + apt: + update_cache: yes + when: ansible_distribution == 'Ubuntu' + +- name: Install system dependencies (Ubuntu) + apt: name={{item}} state=installed + with_items: + - gcc + - python-dev + when: ansible_distribution == 'Ubuntu' + +# Install pip +- name: Download get-pip.py + get_url: + url: "https://bootstrap.pypa.io/get-pip.py" + dest: /tmp/get-pip.py + +- name: Check python-pip exists + stat: path=/usr/bin/pip + register: pip_cmd + +- name: Install python-pip + command: python /tmp/get-pip.py + when: not pip_cmd.stat.exists + +- name: Install pip + yum: pkg=python-pip state=present + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat' + +- name: Ensure httplib2 & boto are present + pip: + name: "{{ item }}" + state: present + with_items: + - httplib2 + - boto diff --git a/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/types.yml b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/types.yml new file mode 100644 index 00000000..0cd8770a --- /dev/null +++ b/org/alien4cloud/automation/a4c/config/location_resources/cfy_byon_v1.3.4/types.yml @@ -0,0 +1,84 @@ +tosca_definitions_version: alien_dsl_1_4_0 + +metadata: + template_name: org.alien4cloud.automation.a4c.config.location_resources.cfy_byon_v1-3-4 + template_version: 1.4.0-SNAPSHOT + template_author: alien4cloud + +imports: + - alien-base-types:1.4.0 + - org.alien4cloud.automation.a4c.config.location:1.4.0-SNAPSHOT + - org.alien4cloud.automation.cloudify.hostpool.pub:1.4.0-SNAPSHOT + - org.alien4cloud.automation.cloudify.manager.pub:1.4.0-SNAPSHOT + - tosca-normative-types:1.0.0-ALIEN14 + +node_types: + + org.alien4cloud.automation.a4c.config.location_resources.cfy_byon_v1-3-4.nodes.ByonLocationResourcesConfigurator: + description: | + Configure a BYON location for A4C 1.3.4 with a single on-demand resource + derived_from: org.alien4cloud.automation.a4c.config.location.nodes.SimpleLocationConfigurator + properties: + type: + type: string + required: true + default: byon + constraints: + - valid_values: [ "byon" ] + resourceType: + type: string + required: true + default: alien.cloudify.byon.nodes.LinuxCompute + resourceName: + type: string + required: true + default: MyResource + resourceArchiveName: + type: string + required: true + default: cloudify-byon-types + resourceArchiveVersion: + type: string + required: true + default: 1.3.4 + resourceAgentInstallMethod: + type: string + required: true + default: none + requirements: + - hostpool: + capability: org.alien4cloud.automation.cloudify.hostpool.pub.capabilities.HostPoolServiceApi + relationship: org.alien4cloud.automation.a4c.config.location_resources.cfy_byon_v1-3-4.LocationConnectsToHostpool + occurrences: [1, 1] + interfaces: + Standard: + start: + # create the location on demand resources + inputs: + ANSIBLE_VERBOSE: false + PLAYBOOK_ENTRY: create_byon_location_resource.yml + orchestratorId: { get_attribute: [HOST, orchestratorId] } + locationId: { get_attribute: [SELF, locationId] } + alien_url: { get_attribute: [HOST, alien_url] } + alien_user: { get_attribute: [HOST, alien_user] } + alien_password: { get_attribute: [HOST, alien_password] } + resourceType: { get_property: [SELF, resourceType] } + resourceName: { get_property: [SELF, resourceName] } + resourceArchiveName: { get_property: [SELF, resourceArchiveName] } + resourceArchiveVersion: { get_property: [SELF, resourceArchiveVersion] } + resourceAgentInstallMethod: { get_property: [SELF, resourceAgentInstallMethod] } + implementation: playbook/playbook.ansible + +relationship_types: + + org.alien4cloud.automation.a4c.config.location_resources.cfy_byon_v1-3-4.LocationConnectsToHostpool: + derived_from: tosca.relationships.ConnectsTo + valid_target_types: [ org.alien4cloud.automation.cloudify.hostpool.pub.capabilities.HostPoolServiceApi ] + interfaces: + Configure: + pre_configure_source: + inputs: + ANSIBLE_VERBOSE: false + PLAYBOOK_ENTRY: connect_hostpool.yml + hostpool_url: { concat: [get_property: [TARGET, cloudify_hostpool, protocol], "://", get_attribute: [TARGET, cloudify_hostpool, ip_address], ":", get_property: [TARGET, cloudify_hostpool, port]] } + implementation: playbook/playbook.ansible