2

When, I'm running a Python script via an Ansible playbook, I get the following error:

fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/Dest/To/Repo/HW.py", "failed": true, "msg": "[Errno 13] Permission denied", "rc": 13} 

I did add the sudo: yes line:

Here is my yaml file:

- name: a play that runs entirely on the ansible host hosts: 127.0.0.1 sudo: yes connection: local tasks: - name: check out a git repository git: repo={{ repo_url }} dest=/Dest/To/Repo/ accept_hostkey=yes vars: repo_url: https://github.com/lorin/mezzanine-example.git - name: Running the Python Script command: /Dest/To/Repo/HW.py 

The HW.py script is just print("Hello World")

Is there anything which I need to do, regarding the permissions error?

4
  • 2
    I can see one possible problem with your script: the HW.py file may not have execution rights. Try the following command: command: /usr/bin/python /Dest/To/Repo/HW.py Commented Jan 27, 2017 at 8:56
  • @SebastianStigler Worked. Pl write it down as an answer :) . However, I get a warning, which says: [DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default). This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. . How do I handle it, in a remote EC2? Commented Jan 27, 2017 at 9:22
  • Please stop using the tag "ansible-ad-hoc" for questions that have nothing to do with Ad-Hoc Commands Commented Jan 27, 2017 at 10:00
  • @Dawny33 just replace the sudo: yes with become: yes Commented Jan 27, 2017 at 15:02

1 Answer 1

4

You need to use umask to add execution rights in you git module call :

- name: a play that runs entirely on the ansible host hosts: 127.0.0.1 sudo: yes connection: local tasks: - name: check out a git repository git: repo={{ repo_url }} dest=/Dest/To/Repo/ accept_hostkey=yes umask: 0022 vars: repo_url: https://github.com/lorin/mezzanine-example.git 
Sign up to request clarification or add additional context in comments.

1 Comment

You need to decide if you use Ansible notation or pure YAML. If you decide for YAML, you need to apply proper indentation for the syntax to be valid. Finally, it's pretty easy to check that the repository in question does not contain HW.py file, so the solution likely would not work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.