Reputation: 3838
I intend to use ansible to deploy a remote file, since the remote location can only be written with 'root', and local file cannot be downloaded with 'root', I use the following playbook:
# in the main playbook
- hosts: master
user: ec2-user
sudo: yes
# in role definition
# download only in the ansible master node
- local_action: get_url url={{ hadoop_mirrors|random }}/hadoop-{{ hadoop_version }}/hadoop-{{ hadoop_version }}.tar.gz dest=/opt/hadoop-{{ hadoop_version }}.tar.gz force=no
sudo: False
register: result
until: result|success
retries: 5
delay: 2
when: hadoop_type_of_node == 'master'
However Ansible seems incapable of reading the line sudo: False
. When I ran this playbook I still got this error:
TASK [ansible-role-hadoop : get_url] **************************************************************************************************
FAILED - RETRYING: ansible-role-hadoop : get_url (5 retries left).
FAILED - RETRYING: ansible-role-hadoop : get_url (4 retries left).
FAILED - RETRYING: ansible-role-hadoop : get_url (3 retries left).
FAILED - RETRYING: ansible-role-hadoop : get_url (2 retries left).
FAILED - RETRYING: ansible-role-hadoop : get_url (1 retries left).
fatal: [54.201.26.110 -> localhost]: FAILED! => {"attempts": 5, "changed": false, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
to retry, use: --limit @/home/peng/git/datapassport/clusterops/ansible/deploy/master.retry
Why is this line not read and what should I do to fix it?
Upvotes: 2
Views: 5918
Reputation: 1447
Privilege Escalation is important to manage in Ansible. The become keyword is the operator for this ability.
4 common uses:
So, sudo: yes, use become:
like this:
- hosts: master
user: ec2-user
become: false
Upvotes: 1
Reputation: 68439
Use become: false
, not sudo: false
which has been deprecated long ago.
sudo
declaration is still kept for compatibility in plays definitions, but for some reason has been not maintained in tasks since Ansible 2.4.
- There is no check for declarations in tasks (you can add foo: bar
to a task and it will be ignored). That's why you don't see any error/warning.
- On the other hand, you should get a warning about sudo
being deprecated.
Upvotes: 6