@@ -6,19 +6,19 @@ import (
66 "os/exec"
77 "strings"
88
9+ "github.com/GearBoxLab/core/command"
910 "github.com/GearBoxLab/core/printer"
10- "github.com/GearBoxLab/core/process"
1111
1212 "github.com/symfony-cli/terminal"
1313)
1414
1515type Ansible struct {
16- processFactory process .Factory
16+ commandFactory command .Factory
1717}
1818
19- func New (processFactory process .Factory ) * Ansible {
19+ func New (commandFactory command .Factory ) * Ansible {
2020 return & Ansible {
21- processFactory : processFactory ,
21+ commandFactory : commandFactory ,
2222 }
2323}
2424
@@ -32,33 +32,33 @@ func (ansible *Ansible) Install(osName, sudoPassword string) (err error) {
3232 if false == installed {
3333 switch osName {
3434 case "oracle-linux" :
35- processes := []* process. Process {
36- ansible .processFactory . NewSudoProcess (sudoPassword , "dnf" , "check-update" , "-y" ),
37- ansible .processFactory . NewSudoProcess (sudoPassword , "dnf" , "upgrade" , "-y" ),
38- ansible .processFactory . NewSudoProcess (sudoPassword , "dnf" , "install" , "-y" , "epel-release" ),
39- ansible .processFactory . NewSudoProcess (sudoPassword , "dnf" , "install" , "-y" , "ansible" ),
35+ commands := []* command. Command {
36+ ansible .commandFactory . NewSudoCommand (sudoPassword , "dnf" , "check-update" , "-y" ),
37+ ansible .commandFactory . NewSudoCommand (sudoPassword , "dnf" , "upgrade" , "-y" ),
38+ ansible .commandFactory . NewSudoCommand (sudoPassword , "dnf" , "install" , "-y" , "epel-release" ),
39+ ansible .commandFactory . NewSudoCommand (sudoPassword , "dnf" , "install" , "-y" , "ansible" ),
4040 }
4141
42- printer .Printf ("\n <comment>$ %s</comment>\n " , processes [0 ].String ())
43- if err = processes [0 ].Run (); err != nil {
42+ printer .Printf ("\n <comment>$ %s</comment>\n " , commands [0 ].String ())
43+ if err = commands [0 ].Run (); err != nil {
4444 var exitError * exec.ExitError
4545 if errors .As (err , & exitError ) && exitError .ExitCode () == 100 {
46- printer .Printf ("\n <comment>$ %s</comment>\n " , processes [1 ].String ())
47- if err = processes [1 ].Run (); err != nil {
46+ printer .Printf ("\n <comment>$ %s</comment>\n " , commands [1 ].String ())
47+ if err = commands [1 ].Run (); err != nil {
4848 return err
4949 }
5050 } else {
5151 return err
5252 }
5353 }
5454
55- printer .Printf ("\n <comment>$ %s</comment>\n " , processes [2 ].String ())
56- if err = processes [2 ].Run (); nil != err {
55+ printer .Printf ("\n <comment>$ %s</comment>\n " , commands [2 ].String ())
56+ if err = commands [2 ].Run (); nil != err {
5757 return err
5858 }
5959
60- printer .Printf ("\n <comment>$ %s</comment>\n " , processes [3 ].String ())
61- if err = processes [3 ].Run (); nil != err {
60+ printer .Printf ("\n <comment>$ %s</comment>\n " , commands [3 ].String ())
61+ if err = commands [3 ].Run (); nil != err {
6262 return err
6363 }
6464 default :
@@ -70,25 +70,25 @@ func (ansible *Ansible) Install(osName, sudoPassword string) (err error) {
7070}
7171
7272func (ansible * Ansible ) RunAnsiblePlaybook (playbookFilePath , variableFilePath , sudoPassword string , args ... string ) (err error ) {
73- proc := ansible .processFactory . NewProcess (
73+ cmd := ansible .commandFactory . NewCommand (
7474 "HISTSIZE=0" ,
7575 "ansible-playbook" ,
7676 playbookFilePath ,
7777 "--extra-vars" , "@" + variableFilePath ,
7878 "--extra-vars" , "ansible_become_password=" + sudoPassword ,
7979 )
80- proc .SetSecretArguments (6 )
80+ cmd .SetSecretArguments (6 )
8181
8282 if terminal .IsVerbose () {
83- proc .AddArguments ("-" + strings .Repeat ("v" , terminal .GetLogLevel ()- 1 ))
83+ cmd .AddArguments ("-" + strings .Repeat ("v" , terminal .GetLogLevel ()- 1 ))
8484 }
8585
8686 if len (args ) > 0 {
87- proc .AddArguments (args ... )
87+ cmd .AddArguments (args ... )
8888 }
8989
90- printer .Printf ("\n <comment>$ %s</comment>\n " , proc .String ())
91- if err = proc .Run (); nil != err {
90+ printer .Printf ("\n <comment>$ %s</comment>\n " , cmd .String ())
91+ if err = cmd .Run (); nil != err {
9292 return err
9393 }
9494
@@ -99,13 +99,13 @@ func (ansible *Ansible) isInstalled() (installed bool, err error) {
9999 var path string
100100 var realPath string
101101
102- if path , err = ansible .processFactory . NewProcess ("which" , "ansible" ).Output (); nil != err && "exit status 1" != err .Error () {
102+ if path , err = ansible .commandFactory . NewCommand ("which" , "ansible" ).Output (); nil != err && "exit status 1" != err .Error () {
103103 return false , err
104104 }
105105 path = strings .TrimSpace (path )
106106
107107 if "" != path {
108- if realPath , err = ansible .processFactory . NewProcess ("ls" , path ).Output (); nil != err {
108+ if realPath , err = ansible .commandFactory . NewCommand ("ls" , path ).Output (); nil != err {
109109 return false , err
110110 }
111111
0 commit comments