Packer is failing with Ansible "You need to be root to perform this command"

1,679 views
Skip to first unread message

Ibrahim Buamod

unread,
Oct 22, 2018, 10:27:08 PM10/22/18
to Packer
I am using packer and the amazon-ebs module but I keep getting this error 

[0;32m    amazon-ebs: fatal: [default]: FAILED! => {"changed": false, "msg": "You need to be root to perform this command.\n", "rc": 1, "results": ["Loaded plugins: priorities, update-motd, upgrade-helper\n"]} [0m

the provisioner 

{
"type": "ansible",
"ansible_env_vars": [ "ANSIBLE_NOCOLOR=True","become_user=root","become=true" ],
"playbook_file": "./Ansible/playbook.yml"
}


the ansible playbook is 

---

- name: Provision Python
hosts: all
gather_facts: no
tasks:
- name: install git
package:
name: git
state: present

Rickard von Essen

unread,
Oct 23, 2018, 2:03:12 AM10/23/18
to packe...@googlegroups.com
"ansible_env_vars": [ "ANSIBLE_NOCOLOR=True","become_user=root","become=true" ],

Is incorrect, it should be:

"ansible_env_vars": [ "ANSIBLE_NOCOLOR=True" ],
"extra_arguments": [ "--become" ],

(and --become-user root can be omitted since that is the default, unless you configured this in a custom config file and need to set it back.)

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/5f8f6b8e-8943-458a-b6d2-6fd050224a95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ibrahim Buamod

unread,
Oct 23, 2018, 2:01:40 PM10/23/18
to Packer
but now I am having this error 

amazon-ebs: fatal: [127.0.0.1]: FAILED! => {"changed": false, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1} [0m

Rickard von Essen

unread,
Oct 23, 2018, 2:08:30 PM10/23/18
to packe...@googlegroups.com
So your user requires password for sudo. You have to allow nopassword in sudoers, look at man sudoers.conf 1). You need to configure this before provisioning, since changing that requires root. On AWS you use user-data/cloud-init for that see 2) and 3)


Reply all
Reply to author
Forward
0 new messages