Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty_print for attributes #70

Closed
Hubbitus opened this issue Jun 21, 2016 · 3 comments
Closed

pretty_print for attributes #70

Hubbitus opened this issue Jun 21, 2016 · 3 comments

Comments

@Hubbitus
Copy link

Hello.

I have tomcat context file which looks like:

<?xml version='1.0' encoding='utf-8'?>
<Context>

    <Resource type="javax.sql.DataSource"
              name="jdbc/UniDataDataSource"
              description="UniData Database"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost:5432/unidata"
              username="postgres"
              password="postgres"
              initialSize="10"
              maxActive="100"
              maxIdle="50"
              minIdle="10"
              suspectTimeout="60"
              timeBetweenEvictionRunsMillis="30000"
              minEvictableIdleTimeMillis="60000"
              testOnBorrow="true"
              validationQuery="SELECT 1"
              validationInterval="30000"
              removeAbandoned="true"
              removeAbandonedTimeout="180"
              logAbandoned="true"
              abandonWhenPercentageFull="50"
              jdbcInterceptors="ResetAbandonedTimer" />

</Context>

I want change their attributes, but do not loose formatting. Is it possible?

My playbook similar to (simplified):

    - name: Provide database access to tomcat
      xml:
        file: context.xml.default
        pretty_print: True
        xpath: /Context/Resource[@name='{{item.name}}']
        attribute: "{{item.attribute}}"
        value: "{{item.value}}"
      with_items:
        - { name: 'jdbc/UniDataDataSource', attribute: url, value: 'test_attribute_value' }

And result in one string:

<?xml version='1.0' encoding='UTF-8'?>
<Context>
  <Resource type="javax.sql.DataSource" name="jdbc/UniDataDataSource" description="UniData Database" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="org.postgresql.Driver" url="test_attribute_value" username="postgres" password="postgres" initialSize="10" maxActive="100" maxIdle="50" minIdle="10" suspectTimeout="60" timeBetweenEvictionRunsMillis="30000" minEvictableIdleTimeMillis="60000" testOnBorrow="true" validationQuery="SELECT 1" validationInterval="30000" removeAbandoned="true" removeAbandonedTimeout="180" logAbandoned="true" abandonWhenPercentageFull="50" jdbcInterceptors="ResetAbandonedTimer"/>
</Context>

I understand what it is Resource tag with many attributes and no child elements. It there any possibility preserve formatting similar to initial state?

@dagwieers
Copy link
Collaborator

The xml module is upstream now (and ships with Ansible v2.4).

Please close this issue, and if needed, open a new issue at: https://github.com/ansible/ansible/issues

@dagwieers
Copy link
Collaborator

dagwieers commented Aug 25, 2017

Yeah, so this is going to be hard to do unless we would hook output-rules to lxml somehow. But you would need to codify the different style-rules the output should consist of. Not sure if lxml can do it, and which ones we would implement, but I am open to add it.

Feel free to migrate this issue to: https://github.com/ansible/ansible/issues

@dagwieers
Copy link
Collaborator

This issue was moved to ansible/ansible#28920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants