1

abc.yml:

d_lab: 192.168.1.1
d_location: /ephemeral
ema:
    apple: 10.0.0.1
    orange: 10.0.0.2
    jack: 10.0.0.3

def.yml:

- name: Load data
  hosts: CENTRAL_host
  any_errors_fatal: yes
  tasks:
    - name: Copy files from ema
      shell: "scp -oStrictHostKeyChecking=no -i ~/.ssh/abc.pem root@{{ ema['item'] }}:/tmp/ /tmp/test/"
      with_items:
        - "{{ items }}"

I am able to access d_lab and d_location, from abc.yml in def.yml. However when I try to access the value of any keys in the dictionary ema(for eg ema[apple]), I am getting the error

" TASK [Copy files from ema] ******************************************************************************************************************* failed: [<>] (item=apple) => {"changed": true, "cmd": "scp -oStrictHostKeyChecking=no -i ~/.ssh/abc.pem root@10.0.0.1:/tmp/ /tmp/test/", "delta": "0:00:00.089524", "end": "2018-05-10 09:15:24.235767", "failed": true, "item": "apple", "rc": 1, "start": "2018-05-10 09:15:24.146243", "stderr": "Warning: Permanently added '10.0.0.1' (RSA) to the list of known hosts.\r\nscp: /tmp: not a regular file", "stderr_lines": ["Warning: Permanently added '10.0.0.1' (RSA) to the list of known hosts.", "scp: /tmp: not a regular file"], "stdout": "", "stdout_lines": []} "

Please let me know how to access a dictionary inside an ansible playbook.

Nathan Villaescusa
  • 17,331
  • 4
  • 53
  • 56

1 Answers1

1

It looks like the actual error that is happening is:

scp: /tmp: not a regular file

Which is likely due to /tmp/ being a directory and not a file on the remote server.

You should be able to recursively copy files by passing the -r argument to scp. See this question for more details.

Nathan Villaescusa
  • 17,331
  • 4
  • 53
  • 56