Skip to content

[CLUST-285] ansible server and client automatically setup - #147

Open
howardyu60211 wants to merge 51 commits into
mainfrom
feat/CLUST-285-ansible-take-over-compute-node
Open

[CLUST-285] ansible server and client automatically setup#147
howardyu60211 wants to merge 51 commits into
mainfrom
feat/CLUST-285-ansible-take-over-compute-node

Conversation

@howardyu60211

Copy link
Copy Markdown
Contributor

Type of changes

  • Feature

Purpose

  • Add Ansible auto setup compute node and control node

Additional Information

@howardyu60211 howardyu60211 self-assigned this Mar 29, 2026
@howardyu60211 howardyu60211 changed the title feat: ansible server and client automatically setup [CLUST-285] ansible server and client automatically setup Apr 28, 2026
@howardyu60211
howardyu60211 marked this pull request as ready for review May 18, 2026 10:50
@howardyu60211
howardyu60211 marked this pull request as draft May 18, 2026 10:51
@yukicoder0509

Copy link
Copy Markdown
Member

I just noticed that we should test this function inside the container. We might need to install an SSH client in the container where our backend lives.

Comment thread internal/ansible/service.go Outdated

if err = s.generateInventory(traceCtx); err != nil {
_, _ = s.queries.UpdateStatus(traceCtx, UpdateStatusParams{ID: id, Status: "failed"})
return Server{}, fmt.Errorf("產生 inventory 失敗: %w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be English log

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated

logger.Info("deploying all nodes...")
if err := exec.Execute(traceCtx); err != nil {
logger.Error("全叢集 Ansible 執行失敗", zap.Error(err))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be English log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated
Comment thread internal/ansible/service.go
Comment thread internal/ansible/service.go Outdated
Comment thread internal/ansible/service.go Outdated
Comment thread internal/ansible/service.go Outdated
Comment thread internal/ansible/service.go Outdated
Comment thread internal/ansible/type.go Outdated
Comment on lines +13 to +22
type AnsibleInventory struct {
All AnsibleGroup `yaml:"all"`
}
type AnsibleGroup struct {
Vars map[string]interface{} `yaml:"vars,omitempty"`
Children map[string]AnsibleChild `yaml:"children,omitempty"`
}
type AnsibleChild struct {
Hosts map[string]HostVars `yaml:"hosts,omitempty"`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be an Ansible prefix, which is the type in the Ansible package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated
InventoryFile = "hosts.yaml"
MainPlaybook = "playbooks/nodes.yaml"
LogFilePath = "ansible-deploy.log"
AnsibleDir = "internal/ansible/ansible"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names typically don't start with the package name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated
}

go s.runAnsibleInBackground(bgCtx, server)
bgCtx := context.WithoutCancel(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use traceCtx here because of the span ID and logging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated

bgCtx := trace.ContextWithSpanContext(context.Background(), span.SpanContext())
go s.runAnsibleInBackground(bgCtx, server)
bgCtx := context.WithoutCancel(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use traceCtx here because of the span ID and logging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated

bgCtx := trace.ContextWithSpanContext(context.Background(), span.SpanContext())
go s.runAnsibleInBackground(bgCtx, server)
bgCtx := context.WithoutCancel(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use traceCtx here because of the span ID and logging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated
"ANSIBLE_CALLBACKS_ENABLED": "profile_tasks",
}),
)
bgCtx := context.WithoutCancel(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use traceCtx here because of the span ID and logging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread internal/ansible/service.go Outdated
bgCtx := trace.ContextWithSpanContext(context.Background(), span.SpanContext())
go s.applySSSDConfig(bgCtx)
if server.AnsibleRole == computeNodeRole {
bgCtx := context.WithoutCancel(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use traceCtx here because of the span ID and logging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants