syncSource sync hosts vars to source.
(newVal value)
| 210 | |
| 211 | // syncSource sync hosts vars to source. |
| 212 | func (v *variable) syncSource(newVal value) error { |
| 213 | v.value.Result = newVal.Result |
| 214 | for hn, hv := range v.value.Hosts { |
| 215 | if reflect.DeepEqual(newVal.Hosts[hn], hv) { |
| 216 | // nothing change skip. |
| 217 | continue |
| 218 | } |
| 219 | if err := v.source.Write(map[string]any{ |
| 220 | "remote": newVal.Hosts[hn].RemoteVars, |
| 221 | "runtime": newVal.Hosts[hn].RuntimeVars, |
| 222 | }, hn); err != nil { |
| 223 | return errors.Wrapf(err, "failed to write host %s variable to source", hn) |
| 224 | } |
| 225 | // update new value to variable |
| 226 | v.value.Hosts[hn] = newVal.Hosts[hn] |
| 227 | } |
| 228 | |
| 229 | return nil |
| 230 | } |