Question

I want to make a script to quickly setup a TINC vpn between computer instances. What I would need is a way to pass through the command line of "/tmp/setup_tinc.py" the following args:

--connect-to %{{ ' '.join( groups['do'] }}%

Where the %{{ part }}% would be interpreted in python. But I can't seem to find a good way to do this. Can you help me fix this code ?

I made the following playbook:

- name: tinc install & setup
  hosts: do
  user: root
  vars:
    tincnet: cloudnet
  tasks:
  - name: Install tinc package
    action: command apt-get install tinc python-argparse -y
  - name: Copy tinc setup script
    action: copy src=setup_tinc.py dest=/tmp/setup_tinc.py mode=755
  - name: Run tinc setup script
    action: command /tmp/setup_tinc.py --network $tincnet --tinc-ip $tinc_ip --hostname     $hostname
  - name: Fetch back the tinc file
    action: fetch src=/etc/tinc/$tincnet/hosts/$hostname dst=hosts
  - name: Adding firewall rule
    action: command ufw allow 514
Was it helpful?

Solution

In Ansible 1.1 and earlier this is a little tricky to do. You can't in-line Python code in playbooks like you can in templates. But the good news is, a few feature in the latest codebase on GitHub (to be released as version 1.2) allows Jinja2-style templating in the playbooks as well! Check this thread out:

https://groups.google.com/forum/#!topic/ansible-project/Gb3ABiEtGtA

So this means you'll be able to do:

--connect-to {{ ' '.join( groups['do'] }}

...right in the playbook if you're using the latest GitHub code.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top