Make use of the template module - templates can do much more than just substitute variable values into text files.
I suggest reading through http://jinja.pocoo.org/docs/dev/templates/ to get an idea of what is possible. Although the examples are most generating html, it can generate any text file format. You can loop through your yaml array to set the languages using a for loop - something like this (not tested) 'language.available' => array({% for item in language.available %}'{{ item }}'{% if not loop.last %}, {% endif %}{% endfor %}), Hope this helps, Jon On Wednesday, December 14, 2016 at 4:24:56 PM UTC, Dick Visser wrote: > > Hi > > Some of my playbooks involve configuring files in languages such as PHP. > The configuration is basically a large PHP array, for example this > SimpleSAMLphp config file: > > <?php > $config = array ( > 'language.i18n.backend' => 'gettext/gettext', > 'template.debug' => true, > 'baseurlpath' => 'wayf/', > 'certdir' => '/etc/simplesamlphp/wayf/cert/', > 'logging.handler' => 'file', > 'loggingdir' => '/var/log/simplesamlphp/wayf/', > 'datadir' => '/var/lib/simplesamlphp/wayf/data/', > 'tempdir' => '/tmp/simplesaml-wayf', > 'attributenamemapdir' => '/etc/simplesamlphp/wayf/attributemap/', > 'secretsalt' => 'secret', > 'auth.adminpassword' => 'secret', > 'logging.processname' => 'simplesamlphp.wayf', > 'language.available' => array('en', 'no', 'nn', 'se', 'da', 'de', 'es', > 'sv', 'fi', 'es', 'fr', 'it', 'nl', 'lb', 'cs', 'sl', 'hr', 'hu', 'pl', > 'pt', 'pt-BR', 'tr', 'ja', 'zh-tw', 'el', 'lt', 'sam', 'ru'), > 'session.cookie.secure' => TRUE, > > etc etc > > The way I now do this is a template with variables such as: > > simplesamlphp_template_debug > simplesamlphp_datadir > simplesamlphp_secretsalt > > There are many possible configuration options, so I'm only using a subset > as ansible variables. > This doesn't really scale well. > Also, it's not just a simple array, but it can be nested as well (see > example above). > > I'm looking for a way to configure things in Ansible using the native data > structure (yaml), and then templating that out to another language. > > So if we consider the above example, you would have this var in a playbook: > > config: > language.i18n.backend: gettext/gettext > template.debug: true > baseurlpath: wayf/ > certdir: /etc/simplesamlphp/wayf/cert/ > logging.handler: file > loggingdir: /var/log/simplesamlphp/wayf/ > datadir: /var/lib/simplesamlphp/wayf/data/ > tempdir: /tmp/simplesaml-wayf > attributenamemapdir: /etc/simplesamlphp/wayf/attributemap/ > secretsalt: secret > auth.adminpassword: secret > language.available: > - en > - no > - nn > - se > - da > - es > - sv > - fi > - fr > - it > logging.processname: simplesamlphp.wayf > session.cookie.secure: TRUE > > > I was thinking about some way to serialize the yaml data structure and > unserialize it using PHP? > But that requires PHP, which is not ideal. > > Any ideas on how I can do this? > > Many thanks > > > > > > > > -- > Dick Visser > Sr. System & Network Engineer > GÉANT > > Want to join us? We're hiring: http://www.geant.org/jobs > -- 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/5f1a28fb-2d93-425e-91f1-1da66eb2f083%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
