"Fossies" - the Fresh Open Source Software Archive

Member "ansible-6.1.0/ansible_collections/community/general/tests/integration/targets/ini_file/tasks/tests/01-value.yml" (12 Jul 2022, 14586 Bytes) of package /linux/misc/ansible-6.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ansible YAML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ---
    2 
    3 ## testing value
    4 
    5 - name: test-value 1 - set "state=present" and "value=null" and "allow_no_value=false" and fail
    6   ini_file:
    7     path: "{{ output_file }}"
    8     section: cars
    9     option: audi
   10     value: null
   11     allow_no_value: false
   12   register: result_value_1
   13   ignore_errors: true
   14 
   15 - name: test-value 1 - verify error message
   16   assert:
   17     that:
   18       - result_value_1 is not changed
   19       - result_value_1 is failed
   20       - result_value_1.msg == "Parameter 'value(s)' must be defined if state=present and allow_no_value=False."
   21 
   22 
   23 - name: test-value 2 - set "state=present" and omit "value" and "allow_no_value=false" and fail
   24   ini_file:
   25     path: "{{ output_file }}"
   26     section: cars
   27     option: audi
   28     allow_no_value: false
   29   register: result_value_2
   30   ignore_errors: true
   31 
   32 - name: test-value 2 - verify error message
   33   assert:
   34     that:
   35       - result_value_2 is not changed
   36       - result_value_2 is failed
   37       - result_value_2.msg == "Parameter 'value(s)' must be defined if state=present and allow_no_value=False."
   38 
   39 
   40 - name: test-value 3 - add "fav=lemonade" in section "[drinks]" in specified file
   41   ini_file:
   42     path: "{{ output_file }}"
   43     section: drinks
   44     option: fav
   45     value: lemonade
   46   register: result3
   47 
   48 - name: test-value 3 - read content from output file
   49   slurp:
   50     src: "{{ output_file }}"
   51   register: output_content
   52 
   53 - name: test-value 3 - set expected content and get current ini file content
   54   set_fact:
   55     expected3: |
   56 
   57       [drinks]
   58       fav = lemonade
   59     content3: "{{ output_content.content | b64decode }}"
   60 
   61 - name: test-value 3 - Verify content of ini file is as expected and ini_file 'changed' is true
   62   assert:
   63     that:
   64       - result3 is changed
   65       - result3.msg == 'section and option added'
   66       - content3 == expected3
   67 
   68 
   69 - name: test-value 4 - add "fav=lemonade" is in section "[drinks]" again
   70   ini_file:
   71     path: "{{ output_file }}"
   72     section: drinks
   73     option: fav
   74     value: lemonade
   75   register: result4
   76 
   77 - name: test-value 4 - Ensure unchanged
   78   assert:
   79     that:
   80       - result4 is not changed
   81       - result4.msg == 'OK'
   82 
   83 
   84 - name: test-value 5 - Ensure "beverage=coke" is in section "[drinks]"
   85   ini_file:
   86     path: "{{ output_file }}"
   87     section: drinks
   88     option: beverage
   89     value: coke
   90   register: result5
   91 
   92 - name: test-value 5 - read content from output file
   93   slurp:
   94     src: "{{ output_file }}"
   95   register: output_content
   96 
   97 - name: test-value 5 - set expected content and get current ini file content
   98   set_fact:
   99     expected5: |
  100 
  101       [drinks]
  102       fav = lemonade
  103       beverage = coke
  104     content5: "{{ output_content.content | b64decode }}"
  105 
  106 - name: test-value 5 - assert 'changed' is true and content is OK
  107   assert:
  108     that:
  109       - result5 is changed
  110       - result5.msg == 'option added'
  111       - content5 == expected5
  112 
  113 
  114 - name: test-value 6 - Remove option "beverage=coke"
  115   ini_file:
  116     path: "{{ output_file }}"
  117     section: drinks
  118     option: beverage
  119     state: absent
  120   register: result6
  121 
  122 - name: test-value 6 - read content from output file
  123   slurp:
  124     src: "{{ output_file }}"
  125   register: output_content
  126 
  127 - name: test-value 6 - set expected content and get current ini file content
  128   set_fact:
  129     expected6: |
  130 
  131       [drinks]
  132       fav = lemonade
  133     content6: "{{ output_content.content | b64decode }}"
  134 
  135 - name: test-value 6 - assert 'changed' is true and content is as expected
  136   assert:
  137     that:
  138       - result6 is changed
  139       - result6.msg == 'option changed'
  140       - content6 == expected6
  141 
  142 
  143 - name: test-value 7 - remove section 'drinks'
  144   ini_file:
  145     path: "{{ output_file }}"
  146     section: drinks
  147     state: absent
  148   register: result7
  149 
  150 - name: test-value 7 - read content from output file
  151   slurp:
  152     src: "{{ output_file }}"
  153   register: output_content
  154 
  155 - name: test-value 7 - get current ini file content
  156   set_fact:
  157     content7: "{{ output_content.content | b64decode }}"
  158 
  159 - name: test-value 7 - assert 'changed' is true and content is empty
  160   assert:
  161     that:
  162       - result7 is changed
  163       - result7.msg == 'section removed'
  164       - content7 == "\n"
  165 
  166 
  167 # allow_no_value
  168 
  169 - name: test-value 8 - test allow_no_value
  170   ini_file:
  171     path: "{{ output_file }}"
  172     section: mysqld
  173     option: skip-name
  174     allow_no_value: yes
  175   register: result8
  176 
  177 - name: test-value 8 - read content from output file
  178   slurp:
  179     src: "{{ output_file }}"
  180   register: output_content
  181 
  182 - name: test-value 8 - set expected content and get current ini file content
  183   set_fact:
  184     content8: "{{ output_content.content | b64decode }}"
  185     expected8: |
  186 
  187       [mysqld]
  188       skip-name
  189 
  190 - name: test-value 8 - assert 'changed' is true and section and option added
  191   assert:
  192     that:
  193       - result8 is changed
  194       - result8.msg == 'section and option added'
  195       - content8 == expected8
  196 
  197 
  198 - name: test-value 9 - test allow_no_value idempotency
  199   ini_file:
  200     path: "{{ output_file }}"
  201     section: mysqld
  202     option: skip-name
  203     allow_no_value: yes
  204   register: result9
  205 
  206 - name: test-value 9 - assert 'changed' is false
  207   assert:
  208     that:
  209       - result9 is not changed
  210       - result9.msg == 'OK'
  211 
  212 
  213 - name: test-value 10 - test create empty section
  214   ini_file:
  215     path: "{{ output_file }}"
  216     section: new_empty_section
  217     allow_no_value: yes
  218   register: result10
  219 
  220 - name: test-value 10 - assert 'changed' is true and section added
  221   assert:
  222     that:
  223       - result10 is changed
  224       - result10.msg == 'only section added'
  225 
  226 
  227 - name: test-value 11 - test create empty section idempotency
  228   ini_file:
  229     path: "{{ output_file }}"
  230     section: new_empty_section
  231     allow_no_value: yes
  232   register: result11
  233 
  234 - name: test-value 11 - assert 'changed' is false
  235   assert:
  236     that:
  237       - result11 is not changed
  238       - result11.msg == 'OK'
  239 
  240 
  241 - name: test-value 12 - test remove empty section
  242   ini_file:
  243     state: absent
  244     path: "{{ output_file }}"
  245     section: new_empty_section
  246     allow_no_value: yes
  247 
  248 - name: test-value 12 - test allow_no_value with loop
  249   ini_file:
  250     path: "{{ output_file }}"
  251     section: mysqld
  252     option: "{{ item.o }}"
  253     value: "{{ item.v | d(omit) }}"
  254     allow_no_value: yes
  255   loop:
  256     - { o: "skip-name-resolve" }
  257     - { o: "max_connections", v: "500" }
  258 
  259 - name: test-value 12 - read content from output file
  260   slurp:
  261     src: "{{ output_file }}"
  262   register: output_content
  263 
  264 - name: test-value 12 - set expected content and get current ini file content
  265   set_fact:
  266     content12: "{{ output_content.content | b64decode }}"
  267     expected12: |
  268 
  269       [mysqld]
  270       skip-name
  271       skip-name-resolve
  272       max_connections = 500
  273   
  274 - name: test-value 12 - Verify content of ini file is as expected
  275   assert:
  276     that:
  277       - content12 == expected12
  278 
  279 
  280 - name: test-value 13 - change option with no value to option with value
  281   ini_file:
  282     path: "{{ output_file }}"
  283     section: mysqld
  284     option: skip-name
  285     value: myvalue
  286   register: result13
  287 
  288 - name: test-value 13 - read content from output file
  289   slurp:
  290     src: "{{ output_file }}"
  291   register: output_content
  292 
  293 - name: test-value 13 - set expected content and get current ini file content
  294   set_fact:
  295     content13: "{{ output_content.content | b64decode }}"
  296     expected13: |
  297 
  298       [mysqld]
  299       skip-name = myvalue
  300       skip-name-resolve
  301       max_connections = 500
  302 
  303 - name: test-value 13 - assert 'changed' and msg 'option changed' and content is as expected
  304   assert:
  305     that:
  306       - result13 is changed
  307       - result13.msg == 'option changed'
  308       - content13 == expected13
  309 
  310 
  311 - name: test-value 14 - change option with value to option with no value
  312   ini_file:
  313     path: "{{ output_file }}"
  314     section: mysqld
  315     option: skip-name
  316     allow_no_value: yes
  317   register: result14
  318 
  319 - name: test-value 14 - read content from output file
  320   slurp:
  321     src: "{{ output_file }}"
  322   register: output_content
  323 
  324 - name: test-value 14 - set expected content and get current ini file content
  325   set_fact:
  326     content14: "{{ output_content.content | b64decode }}"
  327     expected14: |
  328 
  329       [mysqld]
  330       skip-name
  331       skip-name-resolve
  332       max_connections = 500
  333 
  334 - name: test-value 14 - assert 'changed' is true and msg 'option changed' and content is as expected
  335   assert:
  336     that:
  337       - result14 is changed
  338       - result14.msg == 'option changed'
  339       - content14 == expected14
  340 
  341 
  342 - name: test-value 15 - Remove option with no value
  343   ini_file:
  344     path: "{{ output_file }}"
  345     section: mysqld
  346     option: skip-name-resolve
  347     state: absent
  348   register: result15
  349 
  350 - name: test-value 15 - read content from output file
  351   slurp:
  352     src: "{{ output_file }}"
  353   register: output_content
  354 
  355 - name: test-value 15 - set expected content and get current ini file content
  356   set_fact:
  357     content15: "{{ output_content.content | b64decode }}"
  358     expected15: |
  359 
  360       [mysqld]
  361       skip-name
  362       max_connections = 500
  363 
  364 - name: test-value 15 - assert 'changed' is true and msg 'option changed' and content is as expected
  365   assert:
  366     that:
  367       - result15 is changed
  368       - result15.msg == 'option changed'
  369       - content15 == expected15
  370 
  371 
  372 - name: test-value 16 - Clean test file
  373   copy:
  374     content: ""
  375     dest: "{{ output_file }}"
  376     force: yes
  377 
  378 - name: test-value 16 - Ensure "beverage=coke" is created within no section
  379   ini_file:
  380     section:
  381     path: "{{ output_file }}"
  382     option: beverage
  383     value: coke
  384   register: result16
  385 
  386 - name: test-value 16 - read content from output file
  387   slurp:
  388     src: "{{ output_file }}"
  389   register: output_content
  390 
  391 - name: test-value 16 - set expected content and get current ini file content
  392   set_fact:
  393     expected16: |+
  394       beverage = coke
  395       
  396     content16: "{{ output_content.content | b64decode }}"
  397 
  398 - name: test-value 16 - assert 'changed' is true and content is OK (no section)
  399   assert:
  400     that:
  401       - result16 is changed
  402       - result16.msg == 'option added'
  403       - content16 == expected16
  404 
  405 
  406 - name: test-value 17 - Ensure "beverage=coke" is modified as "beverage=water" within no section
  407   ini_file:
  408     path: "{{ output_file }}"
  409     option: beverage
  410     value: water
  411     section:
  412   register: result17
  413 
  414 - name: test-value 17 - read content from output file
  415   slurp:
  416     src: "{{ output_file }}"
  417   register: output_content
  418 
  419 - name: test-value 17 - set expected content and get current ini file content
  420   set_fact:
  421     expected17: |+
  422       beverage = water
  423       
  424     content17: "{{ output_content.content | b64decode }}"
  425 
  426 - name: test-value 17 - assert 'changed' is true and content is OK (no section)
  427   assert:
  428     that:
  429       - result17 is changed
  430       - result17.msg == 'option changed'
  431       - content17 == expected17
  432 
  433 
  434 - name: test-value 18 - remove option 'beverage' within no section
  435   ini_file:
  436     section:
  437     path: "{{ output_file }}"
  438     option: beverage
  439     state: absent
  440   register: result18
  441 
  442 - name: test-value 18 - read content from output file
  443   slurp:
  444     src: "{{ output_file }}"
  445   register: output_content
  446 
  447 - name: test-value 18 - get current ini file content
  448   set_fact:
  449     content18: "{{ output_content.content | b64decode }}"
  450 
  451 - name: test-value 18 - assert 'changed' is true and option is removed (no section)
  452   assert:
  453     that:
  454       - result18 is changed
  455       - result18.msg == 'option changed'
  456       - content18 == "\n"
  457 
  458 
  459 - name: test-value 19 - Check add option without section before existing section
  460   block:
  461     - name: test-value 19 - Add option with section
  462       ini_file:
  463         path: "{{ output_file }}"
  464         section: drinks
  465         option: beverage
  466         value: water
  467     - name: test-value 19 - Add option without section
  468       ini_file:
  469         path: "{{ output_file }}"
  470         section:
  471         option: like
  472         value: tea
  473 
  474 - name: test-value 19 - read content from output file
  475   slurp:
  476     src: "{{ output_file }}"
  477   register: output_content
  478 
  479 - name: test-value 19 - set expected content and get current ini file content
  480   set_fact:
  481     expected19: |
  482       like = tea
  483 
  484       [drinks]
  485       beverage = water
  486     content19: "{{ output_content.content | b64decode }}"
  487 
  488 - name: test-value 19 - Verify content of ini file is as expected
  489   assert:
  490     that:
  491       - content19 == expected19
  492 
  493 
  494 - name: test-value 20 - Check add option with empty string value
  495   block:
  496     - name: test-value 20 - Remove drinks
  497       ini_file:
  498         path: "{{ output_file }}"
  499         section: drinks
  500         state: absent
  501     - name: test-value 20 - Remove tea
  502       ini_file:
  503         path: "{{ output_file }}"
  504         section:
  505         option: like
  506         value: tea
  507         state: absent
  508     # See https://github.com/ansible-collections/community.general/issues/3031
  509     - name: test-value 20 - Tests with empty strings
  510       ini_file:
  511         path: "{{ output_file }}"
  512         section: "{{ item.section | d('extensions') }}"
  513         option: "{{ item.option }}"
  514         value: ""
  515         allow_no_value: "{{ item.no_value | d(omit) }}"
  516       loop:
  517         - option: evolve
  518         - option: regress
  519         - section: foobar
  520           option: foo
  521           no_value: true
  522         - option: improve
  523           no_value: true
  524 
  525 - name: test-value 20 - read content from output file
  526   slurp:
  527     src: "{{ output_file }}"
  528   register: output_content
  529 
  530 - name: test-value 20 - set expected content and get current ini file content
  531   set_fact:
  532     expected20: |+
  533       
  534       [extensions]
  535       evolve = 
  536       regress = 
  537       improve = 
  538       [foobar]
  539       foo = 
  540     content20: "{{ output_content.content | b64decode }}"
  541 
  542 - name: test-value 20 - Verify content of ini file is as expected
  543   assert:
  544     that:
  545       - content20 == expected20
  546 
  547 
  548 - name: test-value 21 - Create starting ini file
  549   copy:
  550     # The content below is the following text file with BOM:
  551     # [section1]
  552     # var1=aaa
  553     # var2=bbb
  554     # [section2]
  555     # var3=ccc
  556     content: !!binary |
  557       77u/W3NlY3Rpb24xXQp2YXIxPWFhYQp2YXIyPWJiYgpbc2VjdGlvbjJdCnZhcjM9Y2NjCg==
  558     dest: "{{ output_file }}"
  559 
  560 - name: test-value 21 -  Test ini breakage
  561   ini_file:
  562     path: "{{ output_file }}"
  563     section: section1
  564     option: var4
  565     value: 0
  566   register: result21
  567 
  568 - name: test-value 21 - read content from output file
  569   slurp:
  570     src: "{{ output_file }}"
  571   register: output_content
  572 
  573 - name: test-value 21 - set expected content and get current ini file content
  574   set_fact:
  575     expected21: |
  576       [section1]
  577       var1=aaa
  578       var2=bbb
  579       var4 = 0
  580       [section2]
  581       var3=ccc
  582     content21: "{{ output_content.content | b64decode }}"
  583 
  584 - name: test-value 21 - Verify content of ini file is as expected
  585   assert:
  586     that:
  587       - result21 is changed
  588       - result21.msg == 'option added'
  589       - content21 == expected21