Reputation: 662
Trying to run a packer build with ansible playbooks, but failing to even start with the most simple task.
I have this as a packer configuration in the provisioners section:
"provisioners": [
{
"type": "ansible",
"playbook_file": "../ansible/main.yml",
"ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True","become=true","become_method=sudo" ]
}
]
And this is the actual playbook content:
- user:
name: foo
comment: "Foo Bar"
Upon execution, this fails for the following reason:
amazon-ebs: fatal: [default]: FAILED! => {"changed": false, "failed": true, "msg": "useradd: Permission denied.\nuseradd: cannot lock /etc/passwd; try again later.\n", "name": "foo", "rc": 1}
As far as I understand, this is because ansible is not running with sudo priviledges on the packer build. How can I resolve this?
Upvotes: 0
Views: 3192
Reputation: 68269
As per documentation ansible_env_vars
is only for environment variables, but become
and become_method
are internal Ansible variables.
Either use extra args in provisioner config:
"extra_arguments": [ "--become" ]
Or add become
into your playbook.
Upvotes: 2