Merge pull request #7274 from rickard-von-essen/ansible-docs

Ansible docs
This commit is contained in:
Rickard von Essen 2019-02-04 20:19:39 +01:00 committed by GitHub
commit 36546c5dfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 25 deletions

View File

@ -51,7 +51,7 @@ type Config struct {
EmptyGroups []string `mapstructure:"empty_groups"`
HostAlias string `mapstructure:"host_alias"`
User string `mapstructure:"user"`
LocalPort string `mapstructure:"local_port"`
LocalPort uint `mapstructure:"local_port"`
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
SFTPCmd string `mapstructure:"sftp_command"`
@ -130,12 +130,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.AnsibleEnvVars = append(p.config.AnsibleEnvVars, "ANSIBLE_SCP_IF_SSH=True")
}
if len(p.config.LocalPort) > 0 {
if _, err := strconv.ParseUint(p.config.LocalPort, 10, 16); err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("local_port: %s must be a valid port", p.config.LocalPort))
}
} else {
p.config.LocalPort = "0"
if p.config.LocalPort > 65535 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("local_port: %d must be a valid port", p.config.LocalPort))
}
if len(p.config.InventoryDirectory) > 0 {
@ -256,11 +252,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
config.AddHostKey(hostSigner)
localListener, err := func() (net.Listener, error) {
port, err := strconv.ParseUint(p.config.LocalPort, 10, 16)
if err != nil {
return nil, err
}
port := p.config.LocalPort
tries := 1
if port != 0 {
tries = 10
@ -272,11 +265,17 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
ui.Say(err.Error())
continue
}
_, p.config.LocalPort, err = net.SplitHostPort(l.Addr().String())
_, portStr, err := net.SplitHostPort(l.Addr().String())
if err != nil {
ui.Say(err.Error())
continue
}
portUint64, err := strconv.ParseUint(portStr, 10, 0)
if err != nil {
ui.Say(err.Error())
continue
}
p.config.LocalPort = uint(portUint64)
return l, nil
}
return nil, errors.New("Error setting up SSH proxy connection")
@ -304,10 +303,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
defer os.Remove(tf.Name())
host := fmt.Sprintf("%s ansible_host=127.0.0.1 ansible_user=%s ansible_port=%s\n",
host := fmt.Sprintf("%s ansible_host=127.0.0.1 ansible_user=%s ansible_port=%d\n",
p.config.HostAlias, p.config.User, p.config.LocalPort)
if p.ansibleMajVersion < 2 {
host = fmt.Sprintf("%s ansible_ssh_host=127.0.0.1 ansible_ssh_user=%s ansible_ssh_port=%s\n",
host = fmt.Sprintf("%s ansible_ssh_host=127.0.0.1 ansible_ssh_user=%s ansible_ssh_port=%d\n",
p.config.HostAlias, p.config.User, p.config.LocalPort)
}

View File

@ -245,13 +245,13 @@ func TestProvisionerPrepare_LocalPort(t *testing.T) {
config["ssh_authorized_key_file"] = publickey_file.Name()
config["playbook_file"] = playbook_file.Name()
config["local_port"] = "65537"
config["local_port"] = uint(65537)
err = p.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
config["local_port"] = "22222"
config["local_port"] = uint(22222)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)

View File

@ -49,7 +49,7 @@ DigitalOcean. Replace the mock `api_token` value with your own.
Required Parameters:
- `playbook_file` - The playbook to be run by Ansible.
- `playbook_file` (string) - The playbook to be run by Ansible.
Optional Parameters:
@ -57,9 +57,7 @@ Optional Parameters:
running Ansible. Usage example:
``` json
{
"ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ]
}
```
If you are running a Windows build on AWS, Azure or Google Compute and
@ -82,9 +80,7 @@ Optional Parameters:
not be quoted. Usage example:
``` json
{
"extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ]
}
```
If you are running a Windows build on AWS, Azure or Google Compute and
@ -117,7 +113,7 @@ Optional Parameters:
inventory directory with `host_vars` `group_vars` that you would like to
use in the playbook that this provisioner will run.
- `local_port` (string) - The port on which to attempt to listen for SSH
- `local_port` (uint) - The port on which to attempt to listen for SSH
connections. This value is a starting point. The provisioner will attempt
listen for SSH connections on the first available of ten ports, starting at
`local_port`. A system-chosen port is used when `local_port` is missing or
@ -175,9 +171,7 @@ To debug underlying issues with Ansible, add `"-vvvv"` to `"extra_arguments"`
to enable verbose logging.
``` json
{
"extra_arguments": [ "-vvvv" ]
}
```
## Limitations

View File

@ -202,7 +202,7 @@
<a href="/docs/provisioners/ansible-local.html">Ansible Local</a>
</li>
<li<%= sidebar_current("docs-provisioners-ansible-remote")%>>
<a href="/docs/provisioners/ansible.html">Ansible Remote</a>
<a href="/docs/provisioners/ansible.html">Ansible (Remote)</a>
</li>
<li<%= sidebar_current("docs-provisioners-breakpoint")%>>
<a href="/docs/provisioners/breakpoint.html">Breakpoint</a>