I need to configure ansible to make ssh connections to my EC2 instances 
based on parameters configure in ec2 tags. I've successfully done this 
using ec2.py script to build dynamic inventory. With this great 
functionality, I've setup 3 tags that contains all what I need to make ssh 
connections to my ec2 hosts, like this example:

- hosts: tag_v3_elasticsearch_prod_True
  vars:
    - ansible_ssh_private_key_file: "{{ ec2_tag_ssh_key | 
default('sv3.key') }}"
    - ansible_ssh_port: "{{ ec2_tag_ssh_port | default(22) }}"
    - ansible_ssh_user: "{{ ec2_tag_ssh_user | default('ubuntu') }}"
  tasks:
    - SOME TASKS....


But, amazon has a limit of 10 tags by ec2 instances (I use many other tags 
associated with my ec2 instances). So, I need to join some tags into one to 
avoid pass this limit. Them, I've an idea to join those 3 ssh tags into one 
using json format, like this:

ssh: {"ssh_key": "prod.key", "ssh_port": "22", "ssh_user": "ansible"}

And them, I've configured my playbook to parse this variable with from_json 
filter. 

---
- hosts: tag_v3_elasticsearch_prod_True
  vars:
    - ssh_private_key_file: "{{ ec2_tag_ssh | from_json }}"
    - ssh_port: "{{ ec2_tag_ssh | from_json }}"
    - ssh_user: "{{ ec2_tag_ssh | from_json }}"
  tasks:
    - debug: var=ssh_private_key_file
    - debug: var=ssh_port
    - debug: var=ssh_user


But, a warning message is displayed to me. It seems that from_json filter 
isn't recognized in playbook vars section.

How can I solve my problem?

[WARNING]: non fatal error while trying to template play variables: Failed 
to
template {{ ec2_tag_ssh | from_json }}: an unexpected type error occurred.
Error was expected string or buffer


PLAY [tag_v3_elasticsearch_prod_True] 
***************************************** 

GATHERING FACTS 
*************************************************************** 
ok: [x.x.x.xxx]

TASK: [debug var=ssh_private_key_file] 
**************************************** 
ok: [x.x.x.xxx] => {
    "var": {
        "ssh_private_key_file": {
            "ssh_key": "prod.pem", 
            "ssh_port": "22", 
            "ssh_user": "ansible"
        }
    }
}

TASK: [debug var=ssh_port] 
**************************************************** 
ok: [x.x.x.xxx] => {
    "var": {
        "ssh_port": {
            "ssh_key": "prod.pem", 
            "ssh_port": "22", 
            "ssh_user": "ansible"
        }
    }
}

TASK: [debug var=ssh_user] 
**************************************************** 
ok: [x.x.x.xxx] => {
    "var": {
        "ssh_user": {
            "ssh_key": "prod.pem", 
            "ssh_port": "22", 
            "ssh_user": "ansible"
        }
    }
}

PLAY RECAP 
******************************************************************** 
x.x.x.xxx             : ok=4    changed=0    unreachable=0    failed=0   




-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f83550e9-8017-4170-b871-98be886e72a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to