---argument_specs:main:short_description: The main entry point for the myapp role
options:myapp_int:type:"int"required:truedescription:"The integer value"myapp_str:type:"str"required:truedescription:"The string value"
# ...(略)...- name: import test
ansible.builtin.import_role:name: test
vars:myapp_int: abc # 文字列myapp_str: hello
こんなエラーになりました。
fatal: [localhost]: FAILED! => {
"argument_errors": [
"argument 'myapp_int' is of type <class 'ansible.parsing.yaml.objects.AnsibleUnicode'> and we were unable to convert to int: <class 'ansible.parsing.yaml.objects.AnsibleUnicode'> cannot be converted to an int"
],
unable to convert to int とあるので、変換しようとしてエラー、ということのようです。 なお、myapp_int: "123" という指定はエラーになりませんでした。
$ ansible-doc -t role -r roles -l
...(略)...
test main The main entry point for the myapp role!!!!
ロール個別表示
ロールと指定すると書く argument のタイプ、説明なども表示されます。
$ ansible-doc -t role -r roles test
> TEST (/home/admin/ansible-ee/roles/test)
ENTRY POINT: main - The main entry point for the myapp role
OPTIONS (= is mandatory):
= kind
kind of sakana
(Choices: kingyo, ugui)
type: str
= myapp_int
The integer value
type: int
= myapp_str
The string value
type: str
まとめ
ロールの実行に必要な変数をチェックする Role argument validation 機能をためしてみました。
$ ansible-playbook -i inventory.ini test.yml
[WARNING]: While constructing a mapping from /home/ansible/test.yml, line 10, column 7, found a duplicate dict key (debug). Using last defined value only.
PLAY [ios] ********************************************************************************************************
TASK [debug] ******************************************************************************************************
ok: [ios01] => {
"msg": "msg2"
}
PLAY RECAP ********************************************************************************************************
ios01 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$ echo $?
0
$ ansible-playbook -i inventory.ini test.yml
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'line'
to see the full traceback, use -vvv
$ echo $?
250
$ ansible-playbook -i inventory.ini test.yml
[WARNING]: Could not match supplied host pattern, ignoring: not_existed
PLAY [not_existed] ************************************************************************************************
skipping: no hosts matched
PLAY RECAP ********************************************************************************************************
$ echo $?
0