From 4750da3457d2c0673bcee1bc3763e368244c521b Mon Sep 17 00:00:00 2001 From: Vespian Date: Fri, 19 Feb 2016 23:43:29 +0100 Subject: [PATCH] Add empty_groups param to ansible provisioner --- provisioner/ansible/provisioner.go | 5 +++++ website/source/docs/provisioners/ansible.html.markdown | 3 +++ 2 files changed, 8 insertions(+) diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index e047cd1e3..8d8760da3 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -43,6 +43,7 @@ type Config struct { // The main playbook file to execute. PlaybookFile string `mapstructure:"playbook_file"` Groups []string `mapstructure:"groups"` + EmptyGroups []string `mapstructure:"empty_groups"` HostAlias string `mapstructure:"host_alias"` LocalPort string `mapstructure:"local_port"` SSHHostKeyFile string `mapstructure:"ssh_host_key_file"` @@ -213,6 +214,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { fmt.Fprintf(w, "[%s]\n%s", group, host) } + for _, group := range p.config.EmptyGroups { + fmt.Fprintf(w, "[%s]\n", group) + } + if err := w.Flush(); err != nil { tf.Close() return fmt.Errorf("Error preparing inventory file: %s", err) diff --git a/website/source/docs/provisioners/ansible.html.markdown b/website/source/docs/provisioners/ansible.html.markdown index 42048e838..19dd6a761 100644 --- a/website/source/docs/provisioners/ansible.html.markdown +++ b/website/source/docs/provisioners/ansible.html.markdown @@ -51,6 +51,9 @@ Optional Parameters: should be placed. When unspecified, the host is not associated with any groups. +- `empty_groups` (array of strings) - The groups which should be present in + inventory file but remain empty. + - `host_alias` (string) - The alias by which the Ansible host should be known. Defaults to `default`.