Tag Archives: dynamic inventory

Accessing ec2.py dynamic inventory variables in templates using Ansible


I’m using Ansible to provision Tomcat, Memcached, Postgres. With static inventory, I’m able to do this hosts [dbservers] db.local [appservers] app1.local app2.local app/tasks/setup_tomcat_app.yml – name: Setup SB ROOT context template: src=root.xml.j2 dest=/var/lib/tomcat7/conf/Catalina/localhost/ROOT.xml notify: – Restart Tomcat tags: – sb_tomcat app/templates/root.xml.j2 {% set dbserver = hostvars[groups[‘dbservers’][0]][‘ansible_eth1’][‘ipv4’][‘address’] %} <resource name="”jdbc/postgres/configuration”" auth="”Container”" factory="”org.apache.tomcat.jdbc.pool.DataSourceFactory”" type="”javax.sql.DataSource”" driverclassname="”org.postgresql.Driver”" url="”jdbc:postgresql://{{dbserver}}:5432/configuration”" ….="" i’m="" […]

https://innopy.wordpress.com/2015/02/13/accessing-ec2-py-dynamic-inventory-variables-in-templates-using-ansible/