Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ping ¶
Ping runs the `ansible all -m ping` command against all nodes found in the provided hosts file by using the mage/sh package to execute the command. If the command execution fails, an error is returned.
**Parameters:**
hostsFile: A string representing the path to the hosts file to be used by the `ansible` command.
**Returns:**
error: An error if the `ansible` command execution fails.
Example ¶
package main import ( "fmt" "io" "os" "github.com/l50/goutils/v2/ansible" ) func main() { hostsFile := "/path/to/your/hosts.ini" // We have to replace the standard output temporarily to capture it. old := os.Stdout r, w, err := os.Pipe() if err != nil { fmt.Fprintln(os.Stderr, err) } os.Stdout = w if err := ansible.Ping(hostsFile); err != nil { fmt.Fprintln(os.Stderr, err) } // Close the Pipe Writer to let the ReadString finish properly. w.Close() // Restore the standard output. os.Stdout = old out, err := io.ReadAll(r) if err != nil { fmt.Fprintln(os.Stderr, err) } // Display the result we've captured. fmt.Print(string(out)) }
Output: localhost | SUCCESS => { "changed": false, "ping": "pong" }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.