Merge branch 'main' of https://github.com/ctrliq/warewulf into main

This commit is contained in:
Niko Kivel
2021-01-28 14:33:25 +01:00
2 changed files with 9 additions and 8 deletions

View File

@@ -83,13 +83,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
w.Close()
w, err = os.OpenFile("/etc/hosts", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer w.Close()
nodes, _ := n.FindAllNodes()
replace.AllNodes = nodes
@@ -97,6 +90,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
replace.Fqdn = controller.Fqdn
if SetShow == false {
// only open "/etc/hosts" when intended to write, as 'os.O_TRUNC' will empty the file otherwise.
w, err = os.OpenFile("/etc/hosts", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer w.Close()
err = tmpl.Execute(w, replace)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)

View File

@@ -16,7 +16,7 @@ var (
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
baseCmd.PersistentFlags().BoolVar(&SetShow, "persist", false, "Persist the configuration and initialize the service")
baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service")
}
// GetRootCommand returns the root cobra.Command for the application.