Simple role to deploy instances
Story: #2002170 Task: #20029 Change-Id: I3fc0ea5144b83262a39593c8211bd88ce90e13f8
This commit is contained in:
@@ -15,6 +15,14 @@ The main entry point to the API is :py:class:`metalsmith.Provisioner`.
|
|||||||
|
|
||||||
api/modules
|
api/modules
|
||||||
|
|
||||||
|
Ansible Role
|
||||||
|
------------
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
user/ansible
|
||||||
|
|
||||||
Indexes
|
Indexes
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
1
doc/source/user/ansible.rst
Normal file
1
doc/source/user/ansible.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.. include:: ../../../roles/metalsmith_deployment/README.rst
|
@@ -4,24 +4,29 @@
|
|||||||
|
|
||||||
- name: Set port argument
|
- name: Set port argument
|
||||||
set_fact:
|
set_fact:
|
||||||
nic: --port test-port
|
nic:
|
||||||
|
port: test-port
|
||||||
when: precreate_port
|
when: precreate_port
|
||||||
|
|
||||||
- name: Set network argument
|
- name: Set network argument
|
||||||
set_fact:
|
set_fact:
|
||||||
nic: --network private
|
nic:
|
||||||
|
network: private
|
||||||
when: not precreate_port
|
when: not precreate_port
|
||||||
|
|
||||||
- name: Deploy a node
|
- name: Deploy a node
|
||||||
command: >
|
include_role:
|
||||||
metalsmith --debug deploy
|
name: metalsmith_deployment
|
||||||
{{ nic }}
|
vars:
|
||||||
--image {{ image }}
|
metalsmith_resource_class: baremetal
|
||||||
--ssh-public-key {{ ssh_key_file }}
|
metalsmith_instances:
|
||||||
--root-disk-size 9
|
- hostname: test
|
||||||
--hostname test
|
image: "{{ image }}"
|
||||||
{{ extra_args }}
|
nics:
|
||||||
baremetal
|
- "{{ nic }}"
|
||||||
|
root_size: 9
|
||||||
|
ssh_public_keys:
|
||||||
|
- "{{ ssh_key_file }}"
|
||||||
|
|
||||||
- name: Get instance info via CLI
|
- name: Get instance info via CLI
|
||||||
command: metalsmith --format=json show test
|
command: metalsmith --format=json show test
|
||||||
|
108
roles/metalsmith_deployment/README.rst
Normal file
108
roles/metalsmith_deployment/README.rst
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
Metalsmith Deployment
|
||||||
|
=====================
|
||||||
|
|
||||||
|
This role deploys instances using **metalsmith** CLI.
|
||||||
|
|
||||||
|
Variables
|
||||||
|
---------
|
||||||
|
|
||||||
|
The only required variable is:
|
||||||
|
|
||||||
|
``metalsmith_instances``
|
||||||
|
list of instances to provision, see Instance_ for instance description.
|
||||||
|
|
||||||
|
The following optional variables provide the defaults for Instance_ attributes:
|
||||||
|
|
||||||
|
``metalsmith_extra_args``
|
||||||
|
the default for ``extra_args``.
|
||||||
|
``metalsmith_image``
|
||||||
|
the default for ``image``.
|
||||||
|
``metalsmith_capabilities``
|
||||||
|
the default for ``capabilities``.
|
||||||
|
``metalsmith_nics``
|
||||||
|
the default for ``nics``.
|
||||||
|
``metalsmith_resource_class``
|
||||||
|
the default for ``resource_class``.
|
||||||
|
``metalsmith_root_size``
|
||||||
|
the default for ``root_size``.
|
||||||
|
``metalsmith_ssh_public_keys``
|
||||||
|
the default for ``ssh_public_keys``.
|
||||||
|
|
||||||
|
Instance
|
||||||
|
--------
|
||||||
|
|
||||||
|
Each instances has the following attributes:
|
||||||
|
|
||||||
|
``extra_args`` (defaults to ``metalsmith_extra_args``)
|
||||||
|
additional arguments to pass to the ``metalsmith`` CLI on all calls.
|
||||||
|
``image`` (defaults to ``metalsmith_image``)
|
||||||
|
UUID or name of the image to use for deployment. Mandatory.
|
||||||
|
``capabilities`` (defaults to ``metalsmith_capabilities``)
|
||||||
|
node capabilities to request when scheduling.
|
||||||
|
``nics`` (defaults to ``metalsmith_nics``)
|
||||||
|
list of virtual NICs to attach to node's physical NICs. Each is an object
|
||||||
|
with exactly one attribute:
|
||||||
|
|
||||||
|
``network``
|
||||||
|
creates a port on the given network, for example:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
nics:
|
||||||
|
- network: private
|
||||||
|
- network: ctlplane
|
||||||
|
|
||||||
|
``port``
|
||||||
|
uses the provided pre-created port:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
nics:
|
||||||
|
- port: b2254316-7867-4615-9fb7-911b3f38ca2a
|
||||||
|
|
||||||
|
``resource_class`` (defaults to ``metalsmith_resource_class``)
|
||||||
|
requested node's resource class. Mandatory.
|
||||||
|
``root_size`` (defaults to ``metalsmith_root_size``)
|
||||||
|
size of the root partition, if partition images are used.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
Also required for whole-disk images due to how the Bare Metal service
|
||||||
|
currently works.
|
||||||
|
|
||||||
|
``ssh_public_keys`` (defaults to ``metalsmith_ssh_public_keys``)
|
||||||
|
list of file names with SSH public keys to put to the node.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- include_role:
|
||||||
|
name: metalsmith_deployment
|
||||||
|
vars:
|
||||||
|
metalsmith_image: centos7
|
||||||
|
metalsmith_nics:
|
||||||
|
- network: ctlplane
|
||||||
|
metalsmith_ssh_public_keys:
|
||||||
|
- /home/user/.ssh/id_rsa.pub
|
||||||
|
metalsmith_instances:
|
||||||
|
- hostname: compute-0
|
||||||
|
resource_class: compute
|
||||||
|
root_size: 100
|
||||||
|
capabilities:
|
||||||
|
boot_mode: uefi
|
||||||
|
- hostname: compute-1
|
||||||
|
resource_class: compute
|
||||||
|
root_size: 100
|
||||||
|
capabilities:
|
||||||
|
boot_mode: uefi
|
||||||
|
- hostname: control-0
|
||||||
|
resource_class: control
|
||||||
|
capabilities:
|
||||||
|
boot_mode: uefi
|
||||||
|
nics:
|
||||||
|
- network: ctlplane
|
||||||
|
- port: 1899af15-149d-47dc-b0dc-a68614eeb5c4
|
6
roles/metalsmith_deployment/defaults/main.yml
Normal file
6
roles/metalsmith_deployment/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Optional parameters
|
||||||
|
metalsmith_capabilities: {}
|
||||||
|
metalsmith_extra_args:
|
||||||
|
metalsmith_nics: []
|
||||||
|
metalsmith_root_size:
|
||||||
|
metalsmith_ssh_public_keys: []
|
1
roles/metalsmith_deployment/meta/main.yml
Normal file
1
roles/metalsmith_deployment/meta/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
allow_duplicates: true
|
37
roles/metalsmith_deployment/tasks/main.yml
Normal file
37
roles/metalsmith_deployment/tasks/main.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Provision instances
|
||||||
|
command: >
|
||||||
|
metalsmith -vv deploy
|
||||||
|
{% for cap_name, cap_value in capabilities.items() %}
|
||||||
|
--capability {{ cap_name }}={{ cap_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% for nic in nics %}
|
||||||
|
{% for nic_type, nic_value in nic.items() %}
|
||||||
|
--{{ nic_type }} {{ nic_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if root_size %}
|
||||||
|
--root-disk-size {{ root_size }}
|
||||||
|
{% endif %}
|
||||||
|
{% for ssh_key in ssh_public_keys %}
|
||||||
|
--ssh-public-key {{ ssh_key }}
|
||||||
|
{% endfor %}
|
||||||
|
--image {{ image }}
|
||||||
|
--hostname {{ instance.hostname }}
|
||||||
|
{{ extra_args }}
|
||||||
|
{{ resource_class }}
|
||||||
|
when: state == 'present'
|
||||||
|
vars:
|
||||||
|
extra_args: "{{ instance.extra_args | default(metalsmith_extra_args) }}"
|
||||||
|
image: "{{ instance.image | default(metalsmith_image) }}"
|
||||||
|
capabilities: "{{ instance.capabilities | default(metalsmith_capabilities) }}"
|
||||||
|
nics: "{{ instance.nics | default(metalsmith_nics) }}"
|
||||||
|
resource_class: "{{ instance.resource_class | default(metalsmith_resource_class) }}"
|
||||||
|
root_size: "{{ instance.root_size | default(metalsmith_root_size) }}"
|
||||||
|
ssh_public_keys: "{{ instance.ssh_public_keys | default(metalsmith_ssh_public_keys) }}"
|
||||||
|
state: "{{ instance.state | default('present') }}"
|
||||||
|
with_items: "{{ metalsmith_instances }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ instance.hostname or instance }}"
|
||||||
|
loop_var: instance
|
@@ -23,6 +23,9 @@ classifier =
|
|||||||
packages =
|
packages =
|
||||||
metalsmith
|
metalsmith
|
||||||
|
|
||||||
|
data_files =
|
||||||
|
share/ansible/roles/metalsmith_deployment = roles/metalsmith_deployment/*
|
||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
metalsmith = metalsmith._cmd:main
|
metalsmith = metalsmith._cmd:main
|
||||||
|
@@ -8,3 +8,4 @@ fixtures>=3.0.0 # Apache-2.0/BSD
|
|||||||
hacking>=1.0.0 # Apache-2.0
|
hacking>=1.0.0 # Apache-2.0
|
||||||
mock>=2.0 # BSD
|
mock>=2.0 # BSD
|
||||||
testtools>=2.2.0 # MIT
|
testtools>=2.2.0 # MIT
|
||||||
|
Pygments>=2.2.0 # BSD
|
||||||
|
2
tox.ini
2
tox.ini
@@ -27,7 +27,7 @@ passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY \
|
|||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands =
|
commands =
|
||||||
flake8 metalsmith
|
flake8 metalsmith
|
||||||
doc8 README.rst doc/source
|
doc8 README.rst doc/source roles
|
||||||
|
|
||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
deps =
|
deps =
|
||||||
|
Reference in New Issue
Block a user