This commit is contained in:
@@ -50,6 +50,11 @@ func (e *Executor) WorkDir() string {
|
||||
return e.workDir
|
||||
}
|
||||
|
||||
// GRPCURL returns the gRPC server URL (host:port)
|
||||
func (e *Executor) GRPCURL() string {
|
||||
return e.grpcServerHost + ":" + e.grpcServerPort
|
||||
}
|
||||
|
||||
// Deploy runs Ansible playbook for the given inventory
|
||||
func (e *Executor) Deploy(
|
||||
ctx context.Context,
|
||||
@@ -66,6 +71,7 @@ func (e *Executor) Deploy(
|
||||
cmd := exec.CommandContext(ctx, "ansible-playbook",
|
||||
"-i", inventoryPath,
|
||||
"-e", fmt.Sprintf("backend_url=%s", e.backendURL),
|
||||
"-e", fmt.Sprintf("grpc_url=%s", e.grpcServerHost+":"+e.grpcServerPort),
|
||||
playbookPath,
|
||||
)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ type InventoryHost struct {
|
||||
Password string
|
||||
DeployType string
|
||||
Token string
|
||||
GRPCURL string
|
||||
}
|
||||
|
||||
// Inventory represents an Ansible inventory file
|
||||
@@ -32,6 +33,7 @@ const inventoryTemplateText = `{{ range .Hosts }}
|
||||
deploy_type={{ .DeployType }}
|
||||
agent_token={{ .Token }}
|
||||
agent_label={{ .Name }}
|
||||
grpc_url={{ .GRPCURL }}
|
||||
|
||||
{{ end }}`
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ansible
|
||||
|
||||
// BinaryDeployPlaybook returns the Ansible playbook for binary deployment
|
||||
// BinaryDeployPlaybook returns the Ansible playbook for binary deployment.
|
||||
// Downloads the agent binary, writes config, and starts it directly (no systemd).
|
||||
// systemd unit is managed separately (e.g. via goreleaser .deb/.rpm packages).
|
||||
const BinaryDeployPlaybook = `---
|
||||
- name: Deploy HellreigN Agent (Binary)
|
||||
hosts: all
|
||||
@@ -11,7 +13,6 @@ const BinaryDeployPlaybook = `---
|
||||
backend_url: "{{ backend_url }}"
|
||||
install_dir: /opt/hellreign
|
||||
bin_name: hellreign-agent
|
||||
service_name: hellreign-agent
|
||||
cert_dir: "{{ install_dir }}/certs"
|
||||
|
||||
tasks:
|
||||
@@ -37,45 +38,29 @@ const BinaryDeployPlaybook = `---
|
||||
copy:
|
||||
content: |
|
||||
backend_url: "{{ backend_url }}"
|
||||
grpc_url: "{{ grpc_url | default('localhost:9001') }}"
|
||||
label: "{{ agent_label }}"
|
||||
registration_token: "{{ agent_token }}"
|
||||
cert_dir: "{{ cert_dir }}"
|
||||
services:
|
||||
- name: system
|
||||
type: journald
|
||||
dest: "{{ install_dir }}/config.yml"
|
||||
mode: '0644'
|
||||
|
||||
- name: Create systemd service file
|
||||
copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=HellreigN Agent
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart={{ install_dir }}/{{ bin_name }}
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
Environment=CONFIG_FILE={{ install_dir }}/config.yml
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/{{ service_name }}.service
|
||||
mode: '0644'
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Enable and start HellreigN Agent service
|
||||
systemd:
|
||||
name: "{{ service_name }}"
|
||||
enabled: yes
|
||||
state: started
|
||||
- name: Start HellreigN Agent
|
||||
shell: |
|
||||
nohup {{ install_dir }}/{{ bin_name }} > /dev/null 2>&1 &
|
||||
echo $!
|
||||
args:
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
CONFIG_FILE: "{{ install_dir }}/config.yml"
|
||||
register: agent_pid
|
||||
changed_when: true
|
||||
`
|
||||
|
||||
// DockerDeployPlaybook returns the Ansible playbook for Docker deployment
|
||||
// DockerDeployPlaybook returns the Ansible playbook for Docker deployment.
|
||||
const DockerDeployPlaybook = `---
|
||||
- name: Deploy HellreigN Agent (Docker)
|
||||
hosts: all
|
||||
@@ -84,6 +69,7 @@ const DockerDeployPlaybook = `---
|
||||
agent_label: "{{ agent_label }}"
|
||||
agent_token: "{{ agent_token }}"
|
||||
backend_url: "{{ backend_url }}"
|
||||
grpc_url: "{{ grpc_url | default('localhost:9001') }}"
|
||||
container_name: hellreign-agent-{{ agent_label }}
|
||||
image: "gitea.d3m0k1d.ru/d3m0k1d/hellreign-agent:latest"
|
||||
cert_dir: /etc/hellreign-agent/certs
|
||||
@@ -117,9 +103,13 @@ const DockerDeployPlaybook = `---
|
||||
copy:
|
||||
content: |
|
||||
backend_url: "{{ backend_url }}"
|
||||
grpc_url: "{{ grpc_url }}"
|
||||
label: "{{ agent_label }}"
|
||||
registration_token: "{{ agent_token }}"
|
||||
cert_dir: "{{ cert_dir }}"
|
||||
services:
|
||||
- name: system
|
||||
type: journald
|
||||
dest: "{{ cert_dir }}/config.yml"
|
||||
mode: '0644'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user