[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/ansible/RFC.md fully. Find ONE feat... #31

Merged
Virgil merged 1 commit from main into dev 2026-04-01 07:14:20 +00:00
2 changed files with 46 additions and 0 deletions

View file

@ -2,6 +2,8 @@ package ansible
import (
"time"
"gopkg.in/yaml.v3"
)
// Playbook represents an Ansible playbook.
@ -13,6 +15,30 @@ type Playbook struct {
Plays []Play `yaml:",inline"`
}
// UnmarshalYAML allows a top-level YAML sequence to decode directly into a
// Playbook wrapper.
func (p *Playbook) UnmarshalYAML(node *yaml.Node) error {
if p == nil {
return nil
}
switch node.Kind {
case yaml.SequenceNode:
return node.Decode(&p.Plays)
case yaml.MappingNode:
var raw struct {
Plays []Play `yaml:"plays"`
}
if err := node.Decode(&raw); err != nil {
return err
}
p.Plays = raw.Plays
return nil
default:
return node.Decode(&p.Plays)
}
}
// Play represents a single play in a playbook.
//
// Example:

View file

@ -8,6 +8,26 @@ import (
"gopkg.in/yaml.v3"
)
// --- Playbook UnmarshalYAML ---
func TestTypes_Playbook_UnmarshalYAML_Good_Sequence(t *testing.T) {
input := `
- name: Bootstrap
hosts: all
tasks:
- debug:
msg: hello
`
var book Playbook
err := yaml.Unmarshal([]byte(input), &book)
require.NoError(t, err)
require.Len(t, book.Plays, 1)
assert.Equal(t, "Bootstrap", book.Plays[0].Name)
assert.Equal(t, "all", book.Plays[0].Hosts)
}
// --- RoleRef UnmarshalYAML ---
func TestTypes_RoleRef_UnmarshalYAML_Good_StringForm(t *testing.T) {