Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy files to server from relative path in ansible

How can I pass a relative path so that Ansible can copy files from node/keys and copy them to a server?

The playbook is ansible/playbook.

My directory structure is:

├── ansible
│   ├── inventory
│   └── playbook
├── node
│   ├── keys
│   ├── index.js
│   ├── node_modules
│   ├── package-lock.json
│   └── utils
└── shell
    ├── data.json
    ├── create-data.sh
    ├── destory.sh
    └── firewall-rules.sh

Below is the playbook:

- hosts: all
  vars:
    source: "{{ source }}"
    destination: /home/ubuntu

  tasks: 

    - name: Copy files
      copy: 
        src:  "{{ source }}"
        dest: "{{ destination }}"

That's how I run:

ansible-playbook -i inventory/inventory.yaml playbook/crypto-generate.yaml
 --extra-vars "source=../node/keys"

I am trying to pass a relative path.

like image 478
TechChain Avatar asked Sep 11 '19 11:09

TechChain


1 Answers

I am using {{ playbook_dir }} to construct full path,see special ansible variables

- name: Copy files
  copy: 
    src:  "{{ playbook_dir }}/../../node/keys"
    dest: "{{ destination }}"
like image 100
ozkolonur Avatar answered Sep 28 '22 02:09

ozkolonur