Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible sudo: sorry, you must have a tty to run sudo

I need to run playbooks on Vagrant boxes and on aws when I setup environment with cloud formation.

In Vagrant file I use ansible-local and everything works fine

name: Setup Unified Catalog Webserver  
    hosts: 127.0.0.1  
    connection: local  
  become: yes  
  become_user: root
  roles: generic

However when I create instance in AWS the ansible playbook fails with error:
sudo: sorry, you must have a tty to run sudo
This happen because it is run as root and it doesnt have tty. But I dont know how to fix it without making change in /etc/sudoers to allow !requiretty

Is there any flags I can setup in ansible.cfg or in my Cloud Formation template?

  "#!/bin/bash\n", "\n", "   
 echo 'Installing Git'\n","  
  yum --nogpgcheck -y install git ansible htop nano wget\n",
 "wget https://s3.eu-central-1.amazonaws.com/XXX -O /root/.ssh/id_rsa\n", 
"chmod 600 /root/.ssh/id_rsa\n", 
"ssh-keyscan 172.31.7.235 >> /root/.ssh/known_hosts\n",
 "git clone [email protected]:something/repo.git /root/repo\n", 
"ansible-playbook /root/env/ansible/test.yml\n
like image 812
Kate Avatar asked Feb 24 '16 08:02

Kate


Video Answer


2 Answers

If you need to specific connection: paramiko within just one playbook versus a global configuration in ansible.cfg, you can add connection: paramiko following in the playbook, example:

- name: Run checks after deployments
  hosts: all
  # https://github.com/paramiko/paramiko/issues/1369
  connection: paramiko
  gather_facts: True
like image 119
hiccupatron Avatar answered Sep 18 '22 08:09

hiccupatron


I was able to fix this by setting the transport = paramiko configuration in ansible.cfg.

like image 43
user8252064 Avatar answered Sep 17 '22 08:09

user8252064