-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible playbook become: true not working when using with packer #13040
Comments
|
I do this in my project with: build {
sources = ["source.vsphere-iso.linux-rhel"]
provisioner "ansible" {
user = var.build_username
galaxy_file = "${path.cwd}/ansible/linux-requirements.yml"
galaxy_force_with_deps = true
playbook_file = "${path.cwd}/ansible/linux-playbook.yml"
roles_path = "${path.cwd}/ansible/roles"
ansible_env_vars = [
"ANSIBLE_CONFIG=${path.cwd}/ansible/ansible.cfg",
"ANSIBLE_PYTHON_INTERPRETER=/usr/libexec/platform-python"
]
extra_arguments = [
"--extra-vars", "display_skipped_hosts=false",
"--extra-vars", "build_username=${var.build_username}",
"--extra-vars", "build_key='${var.build_key}'",
"--extra-vars", "ansible_username=${var.ansible_username}",
"--extra-vars", "ansible_key='${var.ansible_key}'",
"--extra-vars", "enable_cloudinit=${var.vm_guest_os_cloudinit}",
]
} ---
- become: true
become_method: sudo
debugger: never
gather_facts: true
hosts: all
roles:
- base
- users
- configure
- clean |
Duplicate of hashicorp/packer-plugin-ansible#190. Since this is about the ansible plugin, I'll close this now, the discussion can continue on the linked issue. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Overview of the Issue
We are running a simple ansible playbook with ansible provisioner. When running the playbook without packer, the ansible playbook run just fine, but when running with packer, the ansible provisioner keep failing with the error message of
msg: This command has to be run under the root user
.After some investigation, the ansible playbook trigger by packer doesn't seems to elevate to root even defining
become: true
. And we don't seems to be able to make ansible playbook to run as root user. Any help would be appreciated.Here is the the simple ansible playbook I am trying to run
Here is the build block in the packer hcl file
Reproduction Steps
Using packer to provision a Red Hat image in Azure, and use the ansible provisioner to run the playbook in the overview
Plugin and Packer version
Packer version: v1.11.0
Ansible version: v2.10.7
Ansible provisioner version: v1.1.1
Operating system and Environment details
Source server (server runs packer command): Ubuntu
Remote server: Red Hat
The text was updated successfully, but these errors were encountered: