Packer ansible ubuntu vm in azure sudo password required error

444 views
Skip to first unread message

Rajinder Singh

unread,
Nov 7, 2017, 1:03:30 AM11/7/17
to Packer
I am baking a Ubuntu 16.04 VM in Azure.

I tried this

 {

      "type": "ansible",

      "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ],

      "playbook_file": "./hardening_playbook.yml"

 }


and


 {

      "type": "ansible",

      "playbook_file": "./hardening_playbook.yml"

 }




ansible playbook has this:


#5.1.4.7 Set appropriate timeout for sudo.

    - name: sudo timeout

      lineinfile: dest=/etc/sudoers

                   regexp="^Defaults    env_reset"

                   line="Defaults    env_reset,timestamp_timeout=2"

                   state=present



It is failing with this error below


TASK [sudo timeout] ************************************************************

    azure-arm: fatal: [default]: FAILED! => {"changed": false, "failed": true, "module_stderr": "sudo: a password is required\nShared connection to 127.0.0.1 closed.\r\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}

    azure-arm: to retry





Let me know if you have any suggestions.



Thanks

Rickard von Essen

unread,
Nov 7, 2017, 2:34:34 AM11/7/17
to packe...@googlegroups.com
Hard to say with just fragments of your template etc. 

But verify that you have NOPASSWD set in /etc/sudoers.conf for the user connecting to the VM and that it don't require tty (requiretty). 

If those doesn't help you supply a full template and scripts/playbook. 

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/4cdd3a34-1927-4ba2-926c-b3dea9afe475%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alvaro Miranda Aguilera

unread,
Nov 7, 2017, 4:02:09 AM11/7/17
to packe...@googlegroups.com
You can use user_data to fix the /etc/sudoers file

like (may need adjustment)

sed -i -e 's/Defaults\\s*requiretty$/#Defaults\trequiretty/' /etc/sudoers sed -i -e '/# %wheel\tALL=(ALL)\tNOPASSWD: ALL/a %vagrant\tALL=(ALL)\tNOPASSWD: ALL' /etc/sudoers Alvaro.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/4cdd3a34-1927-4ba2-926c-b3dea9afe475%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages