add options to configure host alias and groups
This commit is contained in:
parent
2a46f4001c
commit
0cd54ed19e
|
@ -39,11 +39,13 @@ type Config struct {
|
||||||
ExtraArguments []string `mapstructure:"extra_arguments"`
|
ExtraArguments []string `mapstructure:"extra_arguments"`
|
||||||
|
|
||||||
// The main playbook file to execute.
|
// The main playbook file to execute.
|
||||||
PlaybookFile string `mapstructure:"playbook_file"`
|
PlaybookFile string `mapstructure:"playbook_file"`
|
||||||
LocalPort string `mapstructure:"local_port"`
|
Groups []string `mapstructure:"groups"`
|
||||||
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
|
HostAlias string `mapstructure:"host_alias"`
|
||||||
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
|
LocalPort string `mapstructure:"local_port"`
|
||||||
SFTPCmd string `mapstructure:"sftp_command"`
|
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
|
||||||
|
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
|
||||||
|
SFTPCmd string `mapstructure:"sftp_command"`
|
||||||
inventoryFile string
|
inventoryFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +74,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
p.config.Command = "ansible-playbook"
|
p.config.Command = "ansible-playbook"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.config.HostAlias == "" {
|
||||||
|
p.config.HostAlias = "default"
|
||||||
|
}
|
||||||
|
|
||||||
var errs *packer.MultiError
|
var errs *packer.MultiError
|
||||||
err = validateFileConfig(p.config.PlaybookFile, "playbook_file", true)
|
err = validateFileConfig(p.config.PlaybookFile, "playbook_file", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -196,9 +202,16 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
return fmt.Errorf("Error preparing inventory file: %s", err)
|
return fmt.Errorf("Error preparing inventory file: %s", err)
|
||||||
}
|
}
|
||||||
defer os.Remove(tf.Name())
|
defer os.Remove(tf.Name())
|
||||||
inv := fmt.Sprintf("default ansible_ssh_host=127.0.0.1 ansible_ssh_user=packer-ansible ansible_ssh_port=%s", p.config.LocalPort)
|
|
||||||
_, err = tf.Write([]byte(inv))
|
host := fmt.Sprintf("%s ansible_ssh_host=127.0.0.1 ansible_ssh_user=packer-ansible ansible_ssh_port=%s\n", p.config.HostAlias, p.config.LocalPort)
|
||||||
if err != nil {
|
|
||||||
|
w := bufio.NewWriter(tf)
|
||||||
|
w.WriteString(host)
|
||||||
|
for _, group := range p.config.Groups {
|
||||||
|
fmt.Fprintf(w, "[%s]\n%s", group, host)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.Flush(); err != nil {
|
||||||
tf.Close()
|
tf.Close()
|
||||||
return fmt.Errorf("Error preparing inventory file: %s", err)
|
return fmt.Errorf("Error preparing inventory file: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -214,7 +227,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Cancel() {
|
func (p *Provisioner) Cancel() {
|
||||||
|
|
|
@ -47,6 +47,13 @@ Required Parameters:
|
||||||
|
|
||||||
Optional Parameters:
|
Optional Parameters:
|
||||||
|
|
||||||
|
- `groups` (array of strings) - The groups into which the Ansible host
|
||||||
|
should be placed. When unspecified, the host is not associated with any
|
||||||
|
groups.
|
||||||
|
|
||||||
|
- `host_alias` (string) - The alias by which the Ansible host should be known.
|
||||||
|
Defaults to `default`.
|
||||||
|
|
||||||
- `ssh_host_key_file` (string) - The SSH key that will be used to run the SSH
|
- `ssh_host_key_file` (string) - The SSH key that will be used to run the SSH
|
||||||
server on the host machine to forward commands to the target machine. Ansible
|
server on the host machine to forward commands to the target machine. Ansible
|
||||||
connects to this server and will validate the identity of the server using
|
connects to this server and will validate the identity of the server using
|
||||||
|
@ -71,7 +78,7 @@ Optional Parameters:
|
||||||
should read and write on stdin and stdout, respectively. Defaults to
|
should read and write on stdin and stdout, respectively. Defaults to
|
||||||
`/usr/lib/sftp-server -e`.
|
`/usr/lib/sftp-server -e`.
|
||||||
|
|
||||||
- `extra_arguments` (string) - Extra arguments to pass to Ansible.
|
- `extra_arguments` (array of strings) - Extra arguments to pass to Ansible.
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue