Problem with executing playbook with fetch command.

Hello guys!

I want to share with you my problem which is pretty strange in my point of view.

My playbook looks as follows:

  • name:fetch configuration
    gather_facts: true
    hosts: ‘{{ h }}’
    sudo: true
    sudo_user: admin
    tasks:
  • shell: tar czf /tmp/tomcat-conf.tar.gz /var/test/conf/*
  • fetch: src=/tmp/tomcat-conf.tar.gz dest=/tmp/tomcat-conf-{{ ansible_hostname }} flat=yes

I run this as:

ansible-playbook fetch-conf.yml -e {“h”:“hostname”}

I got error:
ERROR: Expecting property name: line 1 column 1 (char 1)

I don’t have error when I change hosts variable hosts: ‘hostname’ instead of hosts: ‘{{ h }}’

I want to execute this on group of servers that’s why I have to use variable {{ h }}

Anyone can advice/help in this case?

Best Regards,
Marcel

Hi again,

Anybody have idea in this case?

Best Regards,
Marcel

Looks like you need single quote around the extra variable:

ansible-playbook fetch-conf.yml -e ‘{“h”:“hostname”}’

Using key=value also works:

ansible-playbook fetch-conf.yml -e ‘h=hostname’

You also need a space after ‘name:’ on the first line.

Hello Paul,

Cool it works, I didn’t know that this was so much easy :slight_smile: I tried different ways but not came up with this idea.

Thanks and have a nice day!

BR,
Marcel