feat(parser): support FQCN action directives
Some checks are pending
CI / auto-merge (push) Waiting to run
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 10:59:46 +00:00
parent 78eac4e8f2
commit c52d539d3c
2 changed files with 33 additions and 2 deletions

View file

@ -426,6 +426,8 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
"block": true, "rescue": true, "always": true, "notify": true, "listen": true,
"retries": true, "delay": true, "until": true,
"action": true, "local_action": true,
"ansible.builtin.action": true, "ansible.legacy.action": true,
"ansible.builtin.local_action": true, "ansible.legacy.local_action": true,
"include_tasks": true, "import_tasks": true,
"ansible.builtin.include_tasks": true, "ansible.legacy.include_tasks": true,
"ansible.builtin.import_tasks": true, "ansible.legacy.import_tasks": true,
@ -576,7 +578,7 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
// Support legacy action/local_action shorthands.
if t.Module == "" {
if localAction, ok := m["local_action"]; ok {
if localAction, ok := directiveValue(m, "local_action"); ok {
if module, args := parseActionSpec(localAction); module != "" {
t.Module = module
t.Args = args
@ -585,7 +587,7 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
}
}
if t.Module == "" {
if action, ok := m["action"]; ok {
if action, ok := directiveValue(m, "action"); ok {
if module, args := parseActionSpec(action); module != "" {
t.Module = module
t.Args = args

View file

@ -320,6 +320,20 @@ action: command echo hello world
assert.Equal(t, "echo hello world", task.Args["_raw_params"])
}
func TestTypes_Task_UnmarshalYAML_Good_ActionAliasFQCN(t *testing.T) {
input := `
name: Legacy action
ansible.builtin.action: command echo hello world
`
var task Task
err := yaml.Unmarshal([]byte(input), &task)
require.NoError(t, err)
assert.Equal(t, "command", task.Module)
require.NotNil(t, task.Args)
assert.Equal(t, "echo hello world", task.Args["_raw_params"])
}
func TestTypes_Task_UnmarshalYAML_Good_ActionAliasKeyValue(t *testing.T) {
input := `
name: Legacy action with args
@ -351,6 +365,21 @@ local_action: shell echo local
assert.Equal(t, "echo local", task.Args["_raw_params"])
}
func TestTypes_Task_UnmarshalYAML_Good_LocalActionFQCN(t *testing.T) {
input := `
name: Legacy local action
ansible.legacy.local_action: shell echo local
`
var task Task
err := yaml.Unmarshal([]byte(input), &task)
require.NoError(t, err)
assert.Equal(t, "shell", task.Module)
assert.Equal(t, "localhost", task.Delegate)
require.NotNil(t, task.Args)
assert.Equal(t, "echo local", task.Args["_raw_params"])
}
func TestTypes_Task_UnmarshalYAML_Good_LocalActionKeyValue(t *testing.T) {
input := `
name: Legacy local action with args