Doefi
Doefi

Reputation: 79

Fetching current path of the file using Ansible

In Ansible, i need to take a parent directory or current path of file automatically, in some of chef framework we have chef::config,it ll take automatically file path.

e.g:
  /tasks/main.yml:

    name: execute cmd
    command: python file.py

If I have my "file.py" in a tasks folder, I need to execute my playbook from that path only like: /home/playbook/roles/sample/tasks ,then only it taking a script file and running.Suppose when i run from root path i mean /home/playbook/ path,it shows "No such file or directory"

I have tried lookup(env,HOME), It just takes /home alone but not related to that file path.

So to take a current file path how to give in ansible???

Thanks

Upvotes: 0

Views: 3207

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

Answer from comments

script module will copy the file first and then run it. if you use roles, you should place scripts into roles/my_role/files folder.

Upvotes: 2

Related Questions