Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultSSHInventoryFilev1 = "{{ .HostAlias }} ansible_ssh_host={{ .Host }} ansible_ssh_user={{ .User }} ansible_ssh_port={{ .Port }}\n"
View Source
const DefaultSSHInventoryFilev2 = "{{ .HostAlias }} ansible_host={{ .Host }} ansible_user={{ .User }} ansible_port={{ .Port }}\n"
View Source
const DefaultWinRMInventoryFilev2 = "" /* 176-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { common.PackerConfig `mapstructure:",squash"` // The command to invoke ansible. Defaults to // `ansible-playbook`. If you would like to provide a more complex command, // for example, something that sets up a virtual environment before calling // ansible, take a look at the ansible wrapper guide below for inspiration. // Please note that Packer expects Command to be a path to an executable. // Arbitrary bash scripting will not work and needs to go inside an // executable script. Command string `mapstructure:"command"` // Extra arguments to pass to Ansible. These arguments _will not_ be passed // through a shell and arguments should not be quoted. Usage example: // // “`json // "extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ] // “` // // In certain scenarios where you want to pass ansible command line // arguments that include parameter and value (for example // `--vault-password-file pwfile`), from ansible documentation this is // correct format but that is NOT accepted here. Instead you need to do it // like `--vault-password-file=pwfile`. // // If you are running a Windows build on AWS, Azure, Google Compute, or // OpenStack and would like to access the auto-generated password that // Packer uses to connect to a Windows instance via WinRM, you can use the // template variable // // “`build.Password“` in HCL templates or “`{{ build `Password`}}“` in // legacy JSON templates. For example: // // in JSON templates: // // “`json // "extra_arguments": [ // "--extra-vars", "winrm_password={{ build `Password`}}" // ] // “` // // in HCL templates: // // “`hcl // extra_arguments = [ // "--extra-vars", "winrm_password=${build.Password}" // ] // “` // // If the lefthand side of a value contains 'secret' or 'password' (case // insensitive) it will be hidden from output. For example, passing // "my_password=secr3t" will hide "secr3t" from output. ExtraArguments []string `mapstructure:"extra_arguments"` // Environment variables to set before // 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" ] // “` // // This is a [template engine](/packer/docs/templates/legacy_json_templates/engine). Therefore, you // may use user variables and template functions in this field. // // For example, if you are running a Windows build on AWS, Azure, // Google Compute, or OpenStack and would like to access the auto-generated // password that Packer uses to connect to a Windows instance via WinRM, you // can use the template variable `{{.WinRMPassword}}` in this option. Example: // // “`json // "ansible_env_vars": [ "WINRM_PASSWORD={{.WinRMPassword}}" ], // “` AnsibleEnvVars []string `mapstructure:"ansible_env_vars"` // The playbook to be run by Ansible. PlaybookFile string `mapstructure:"playbook_file" required:"true"` // Specifies --ssh-extra-args on command line defaults to -o IdentitiesOnly=yes AnsibleSSHExtraArgs []string `mapstructure:"ansible_ssh_extra_args"` // The groups into which the Ansible host should // be placed. When unspecified, the host is not associated with any groups. Groups []string `mapstructure:"groups"` // The groups which should be present in // inventory file but remain empty. EmptyGroups []string `mapstructure:"empty_groups"` // The alias by which the Ansible host should be // known. Defaults to `default`. This setting is ignored when using a custom // inventory file. HostAlias string `mapstructure:"host_alias"` // The `ansible_user` to use. Defaults to the user running // packer, NOT the user set for your communicator. If you want to use the same // user as the communicator, you will need to manually set it again in this // field. User string `mapstructure:"user"` // 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 // empty. LocalPort int `mapstructure:"local_port"` // The SSH key that will be used to run the SSH // 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 the system known_hosts. The default behavior is to generate // and use a onetime key. Host key checking is disabled via the // `ANSIBLE_HOST_KEY_CHECKING` environment variable if the key is generated. SSHHostKeyFile string `mapstructure:"ssh_host_key_file"` // The SSH public key of the Ansible // `ssh_user`. The default behavior is to generate and use a onetime key. If // this key is generated, the corresponding private key is passed to // `ansible-playbook` with the `-e ansible_ssh_private_key_file` option. SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"` // Change the key type used for the adapter. // // Supported values: // // * ECDSA (default) // * RSA // // NOTE: using RSA may cause problems if the key is used to authenticate with rsa-sha1 // as modern OpenSSH versions reject this by default as it is unsafe. AdapterKeyType string `mapstructure:"ansible_proxy_key_type"` // The command to run on the machine being // provisioned by Packer to handle the SFTP protocol that Ansible will use to // transfer files. The command should read and write on stdin and stdout, // respectively. Defaults to `/usr/lib/sftp-server -e`. SFTPCmd string `mapstructure:"sftp_command"` // Check if ansible is installed prior to // running. Set this to `true`, for example, if you're going to install // ansible during the packer run. SkipVersionCheck bool `mapstructure:"skip_version_check"` UseSFTP bool `mapstructure:"use_sftp"` // The directory in which to place the // temporary generated Ansible inventory file. By default, this is the // system-specific temporary file location. The fully-qualified name of this // temporary file will be passed to the `-i` argument of the `ansible` command // when this provisioner runs ansible. Specify this if you have an existing // inventory directory with `host_vars` `group_vars` that you would like to // use in the playbook that this provisioner will run. InventoryDirectory string `mapstructure:"inventory_directory"` // This template represents the format for the lines added to the temporary // inventory file that Packer will create to run Ansible against your image. // The default for recent versions of Ansible is: // "{{ .HostAlias }} ansible_host={{ .Host }} ansible_user={{ .User }} ansible_port={{ .Port }}\n" // Available template engines are: This option is a template engine; // variables available to you include the examples in the default (Host, // HostAlias, User, Port) as well as any variables available to you via the // "build" template engine. InventoryFileTemplate string `mapstructure:"inventory_file_template"` // The inventory file to use during provisioning. // When unspecified, Packer will create a temporary inventory file and will // use the `host_alias`. InventoryFile string `mapstructure:"inventory_file"` // If `true`, the Ansible provisioner will // not delete the temporary inventory file it creates in order to connect to // the instance. This is useful if you are trying to debug your ansible run // and using "--on-error=ask" in order to leave your instance running while you // test your playbook. this option is not used if you set an `inventory_file`. KeepInventoryFile bool `mapstructure:"keep_inventory_file"` // A requirements file which provides a way to // install roles or collections with the [ansible-galaxy // cli](https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#the-ansible-galaxy-command-line-tool) // on the local machine before executing `ansible-playbook`. By default, this is empty. GalaxyFile string `mapstructure:"galaxy_file"` // The command to invoke ansible-galaxy. By default, this is // `ansible-galaxy`. GalaxyCommand string `mapstructure:"galaxy_command"` // Force overwriting an existing role. // Adds `--force` option to `ansible-galaxy` command. By default, this is // `false`. GalaxyForceInstall bool `mapstructure:"galaxy_force_install"` // Force overwriting an existing role and its dependencies. // Adds `--force-with-deps` option to `ansible-galaxy` command. By default, // this is `false`. GalaxyForceWithDeps bool `mapstructure:"galaxy_force_with_deps"` // The path to the directory on your local system in which to // install the roles. Adds `--roles-path /path/to/your/roles` to // `ansible-galaxy` command. By default, this is empty, and thus `--roles-path` // option is not added to the command. RolesPath string `mapstructure:"roles_path"` // The path to the directory on your local system in which to // install the collections. Adds `--collections-path /path/to/your/collections` to // `ansible-galaxy` command. By default, this is empty, and thus `--collections-path` // option is not added to the command. CollectionsPath string `mapstructure:"collections_path"` // When `true`, set up a localhost proxy adapter // so that Ansible has an IP address to connect to, even if your guest does not // have an IP address. For example, the adapter is necessary for Docker builds // to use the Ansible provisioner. If you set this option to `false`, but // Packer cannot find an IP address to connect Ansible to, it will // automatically set up the adapter anyway. // // In order for Ansible to connect properly even when use_proxy is false, you // need to make sure that you are either providing a valid username and ssh key // to the ansible provisioner directly, or that the username and ssh key // being used by the ssh communicator will work for your needs. If you do not // provide a user to ansible, it will use the user associated with your // builder, not the user running Packer. // use_proxy=false is currently only supported for SSH and WinRM. // // Currently, this defaults to `true` for all connection types. In the future, // this option will be changed to default to `false` for SSH and WinRM // connections where the provisioner has access to a host IP. UseProxy config.Trilean `mapstructure:"use_proxy"` // Force WinRM to use HTTP instead of HTTPS. // // Set this to true to force Ansible to use HTTP instead of HTTPS to communicate // over WinRM to the destination host. // // Ansible uses the port as a heuristic to determine whether to use HTTP // or not. In the current state, Packer assigns a random port for connecting // to WinRM and Ansible's heuristic fails to determine that it should be // using HTTP, even when the communicator is setup to use it. // // Alternatively, you may also directly add the following arguments to the // `extra_arguments` section for ansible: `"-e", "ansible_winrm_scheme=http"`. // // Default: `false` WinRMUseHTTP bool `mapstructure:"ansible_winrm_use_http"` // contains filtered or unexported fields }
type FlatConfig ¶
type FlatConfig struct { PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"` PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"` PackerCoreVersion *string `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"` PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"` PackerForce *bool `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"` PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"` PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` Command *string `mapstructure:"command" cty:"command" hcl:"command"` ExtraArguments []string `mapstructure:"extra_arguments" cty:"extra_arguments" hcl:"extra_arguments"` AnsibleEnvVars []string `mapstructure:"ansible_env_vars" cty:"ansible_env_vars" hcl:"ansible_env_vars"` PlaybookFile *string `mapstructure:"playbook_file" required:"true" cty:"playbook_file" hcl:"playbook_file"` AnsibleSSHExtraArgs []string `mapstructure:"ansible_ssh_extra_args" cty:"ansible_ssh_extra_args" hcl:"ansible_ssh_extra_args"` Groups []string `mapstructure:"groups" cty:"groups" hcl:"groups"` EmptyGroups []string `mapstructure:"empty_groups" cty:"empty_groups" hcl:"empty_groups"` HostAlias *string `mapstructure:"host_alias" cty:"host_alias" hcl:"host_alias"` User *string `mapstructure:"user" cty:"user" hcl:"user"` LocalPort *int `mapstructure:"local_port" cty:"local_port" hcl:"local_port"` SSHHostKeyFile *string `mapstructure:"ssh_host_key_file" cty:"ssh_host_key_file" hcl:"ssh_host_key_file"` SSHAuthorizedKeyFile *string `mapstructure:"ssh_authorized_key_file" cty:"ssh_authorized_key_file" hcl:"ssh_authorized_key_file"` AdapterKeyType *string `mapstructure:"ansible_proxy_key_type" cty:"ansible_proxy_key_type" hcl:"ansible_proxy_key_type"` SFTPCmd *string `mapstructure:"sftp_command" cty:"sftp_command" hcl:"sftp_command"` SkipVersionCheck *bool `mapstructure:"skip_version_check" cty:"skip_version_check" hcl:"skip_version_check"` UseSFTP *bool `mapstructure:"use_sftp" cty:"use_sftp" hcl:"use_sftp"` InventoryDirectory *string `mapstructure:"inventory_directory" cty:"inventory_directory" hcl:"inventory_directory"` InventoryFileTemplate *string `mapstructure:"inventory_file_template" cty:"inventory_file_template" hcl:"inventory_file_template"` InventoryFile *string `mapstructure:"inventory_file" cty:"inventory_file" hcl:"inventory_file"` KeepInventoryFile *bool `mapstructure:"keep_inventory_file" cty:"keep_inventory_file" hcl:"keep_inventory_file"` GalaxyFile *string `mapstructure:"galaxy_file" cty:"galaxy_file" hcl:"galaxy_file"` GalaxyCommand *string `mapstructure:"galaxy_command" cty:"galaxy_command" hcl:"galaxy_command"` GalaxyForceInstall *bool `mapstructure:"galaxy_force_install" cty:"galaxy_force_install" hcl:"galaxy_force_install"` GalaxyForceWithDeps *bool `mapstructure:"galaxy_force_with_deps" cty:"galaxy_force_with_deps" hcl:"galaxy_force_with_deps"` RolesPath *string `mapstructure:"roles_path" cty:"roles_path" hcl:"roles_path"` CollectionsPath *string `mapstructure:"collections_path" cty:"collections_path" hcl:"collections_path"` UseProxy *bool `mapstructure:"use_proxy" cty:"use_proxy" hcl:"use_proxy"` WinRMUseHTTP *bool `mapstructure:"ansible_winrm_use_http" cty:"ansible_winrm_use_http" hcl:"ansible_winrm_use_http"` }
FlatConfig is an auto-generated flat version of Config. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type Provisioner ¶
type Provisioner struct {
// contains filtered or unexported fields
}
func (*Provisioner) ConfigSpec ¶
func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec
func (*Provisioner) Prepare ¶
func (p *Provisioner) Prepare(raws ...interface{}) error
Click to show internal directories.
Click to hide internal directories.