mirror of https://github.com/ansible/ansible.git
Introduce 'insertbefore' and 'insertafter' to specify the position (#44811)
* Introduce 'insertbefore' and 'insertafter' to specify the position children have to be inserted. * Added version_added to new options * Xpath in example needs single quotes * Added integration tests for insertafter and insertbefore * Changed version_added to 2.8pull/50353/head
parent
1793cad07b
commit
2dbade4adc
@ -0,0 +1,17 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<business type="bar">
|
||||
<name>Tasty Beverage Co.</name>
|
||||
<beers>
|
||||
<beer>Rochefort 10</beer>
|
||||
<beer>St. Bernardus Abbot 12</beer>
|
||||
<beer>Old Rasputin</beer>
|
||||
<beer>Old Motor Oil</beer>
|
||||
<beer>Old Curmudgeon</beer>
|
||||
<beer>Schlitz</beer>
|
||||
</beers>
|
||||
<rating subjective="true">10</rating>
|
||||
<website>
|
||||
<mobilefriendly/>
|
||||
<address>http://tastybeverageco.com</address>
|
||||
</website>
|
||||
</business>
|
@ -0,0 +1,17 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<business type="bar">
|
||||
<name>Tasty Beverage Co.</name>
|
||||
<beers>
|
||||
<beer>Rochefort 10</beer>
|
||||
<beer>Old Rasputin</beer>
|
||||
<beer>Old Motor Oil</beer>
|
||||
<beer>Old Curmudgeon</beer>
|
||||
<beer>St. Bernardus Abbot 12</beer>
|
||||
<beer>Schlitz</beer>
|
||||
</beers>
|
||||
<rating subjective="true">10</rating>
|
||||
<website>
|
||||
<mobilefriendly/>
|
||||
<address>http://tastybeverageco.com</address>
|
||||
</website>
|
||||
</business>
|
@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: '/business/beers/beer[text()="St. Bernardus Abbot 12"]'
|
||||
insertafter: yes
|
||||
add_children:
|
||||
- beer: Old Rasputin
|
||||
- beer: Old Motor Oil
|
||||
- beer: Old Curmudgeon
|
||||
pretty_print: yes
|
||||
register: add_children_insertafter
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-insertafter.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- add_children_insertafter.changed == true
|
||||
- comparison.changed == false # identical
|
@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: '/business/beers/beer[text()="St. Bernardus Abbot 12"]'
|
||||
insertbefore: yes
|
||||
add_children:
|
||||
- beer: Old Rasputin
|
||||
- beer: Old Motor Oil
|
||||
- beer: Old Curmudgeon
|
||||
pretty_print: yes
|
||||
register: add_children_insertbefore
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-insertbefore.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- add_children_insertbefore.changed == true
|
||||
- comparison.changed == false # identical
|
Loading…
Reference in New Issue