YAML フィールド
検証とファイルインポートに対応した YAML エディターで扱う構造化データです
プロパティ
yaml フィールドで使用できるプロパティを、用途別にまとめています。
| 属性 | 説明 |
|---|---|
| basic | |
| name string / 必須 / 一意 | Field name
This attribute represents the name of the form field. |
| type string / 必須 | Field type
Other attributes might only be available for some field types. 値: yaml |
| label string | Field label
A friendly name/label for the field. Note: if not set, the field name is used as label, but not when type is html. Since 6.0.3: Supports placeholders for dynamic labels (e.g., |
| help string | Field help message
Some fields require additional help information. This help message will be shown below the field. Since 6.0.3: Supports placeholders for dynamic help text (e.g., |
| subform string / 必須 | Name of the subform that defines one row
For a |
| data | |
| default many | Default value
The type of the value depends on the field type.
For |
| expression string | A javascript expression.
By default this javascript is evaluated on the server side and limited to predefined functions (for security). However in combination with tip: use the alias |
| runLocal boolean | Run an expression locally
When running expressions, by default they are run remotely on the server. 既定値: false |
| dbConfig string, array or object | A database connection
When you want to query data from a database, you will need the proper connection information. |
| query string | The query to select data from a database
This is typically a classic SELECT statement. Every |
| interaction | |
| dependencyFn string バージョン 4.0.0 で追加 | The dependency logical function
This attribute represents the logical function between multiple dependencies. 選択肢:
|
| dependencies list / elements=object | Show/hide this field based on the values or other fields
Each dependency element is either an object with the following 2 attributes:
Or with the following 2 attributes:
Use in combination with attribute |
| showLoadButton boolean バージョン 6.1.5 で追加 | Show load button for file import
Enables a “Load YAML” button that allows users to import data from .yml or .yaml files. For list fields, the YAML file must contain a valid array of objects. For yaml fields, the file can contain any valid YAML structure. Single objects are automatically wrapped in arrays for list fields. 既定値: false |
| showDownloadButton boolean バージョン 6.1.5 で追加 | Show download button for file export
Enables a “Download” button that exports the field content as a .yml file. The filename is automatically generated from the field name. 既定値: false |
| readonly boolean バージョン 6.1.5 で追加 | Display YAML in readonly mode
When set to true, displays the YAML content with syntax highlighting in a non-editable card. Useful for showing computed or retrieved YAML data without allowing modifications. The field uses v-highlightjs for pretty syntax-highlighted display. 既定値: false |
| output | |
| output boolean バージョン 6.2.0 で追加 | Include field value as extravar
Form fields are by default sent as extravars. 既定値: true |
| model string or array | Extravar modelling
By default, a field is sent as a root-extravar. |
| security | |
| noLog boolean バージョン 2.2.3 で追加 | Disable backend logging
Disables logging in the backend, to hide passwords for example. 既定値: false |
| validation | |
| required boolean | Required field
Makes the field required. 既定値: false |
| validIf object バージョン 2.2.4 で追加 | An field based validation (field must be true)
Enforces a validation where a referencing (expression) field must be true. This field requires an object with 2 attributes:
|
| validIfNot object バージョン 2.2.4 で追加 | An field based validation (field must be false)
Enforces a validation where a referencing (expression) field must be false. This field requires an object with 2 attributes:
|
| ignoreIncomplete boolean | Allow form submit on non-evaluated placeholders
When an expression-based field has placeholders, 既定値: false |
| yamlError object バージョン 6.1.5 で追加 | Custom YAML validation error message
Allows you to customize the error message displayed when YAML syntax validation fails. The yamlError object requires a |
| visualization | |
| group string | The field group name
With this attribute you can group fields together. |
| line string バージョン 4.0.3 で追加 | The field line name
With this attribute you can group fields in a single line together. |
| width string バージョン 4.0.3 で追加 | The field width
With this attribute you can set the width of a field. 選択肢:
|
例
yaml フィールドの YAML での例です。
Manual YAML editing
YAML でのフィールド定義です。
- type: yaml
name: config
label: Application Configuration
default:
database:
host: localhost
port: 5432
features:
- authentication
- logging
showLoadButton: true
showDownloadButton: true
yamlError:
description: "Please enter valid YAML configuration"
required: true
YAML from expression
YAML でのフィールド定義です。
- type: yaml
name: users
label: User List
expression: fn.fnRestBasic('get','https://api.example.com/users','','','')
showDownloadButton: true
readonly: true
YAML from local expression
YAML でのフィールド定義です。
- type: yaml
name: computed_config
label: Computed Config
runLocal: true
expression: |
(()=>{
return {
env: 'production',
settings: $(environment_field)
};
})()
showDownloadButton: true
YAML from query
YAML でのフィールド定義です。
- type: yaml
name: database_data
label: Database Records
query: "SELECT * FROM servers"
dbConfig: mydb
showDownloadButton: true
__parent__ で親フォームのデータを参照する
yaml フィールドが subform モードを使う場合、AnsibleForms はサブフォームに __parent__ 変数を注入します。この変数には、エディターを開いた時点での 親フォームのすべてのフィールド値 のスナップショットが入っており、定数や vars も含まれます。
サブフォームのフィールド定義では、標準の $(...) 式の構文でこの変数を参照します。
- name: NetworkConfig
type: subform
fields:
- name: interface
type: text
label: Interface
required: true
- name: vlan
type: enum
label: VLAN
# filter available VLANs based on the parent's selected region
query: "select id,name from vlans where region='$(__parent__.region)'"
dbConfig: MYDB # a database of Connections > Databases
valueColumn: id
placeholderColumn: name
- name: mtu
type: number
label: MTU
# default to 9000 in production, 1500 elsewhere
default: "'$(__parent__.environment)' === 'production' ? 9000 : 1500"
evalDefault: true
- name: Configure server
type: ansible
playbook: configure.yml
roles: [default]
fields:
- name: environment
type: enum
values: [dev, staging, production]
- name: region
type: enum
values: [eu-west-1, us-east-1, ap-southeast-1]
- name: nic
type: yaml
label: Network interface
subform: NetworkConfig
__parent__は フロントエンド専用 のヘルパーです。Ansible の extravars からは取り除かれ、playbook に送られることはありません。