how to dynamic update value in vars_file

I have a var file like

`
nodes:

  • name: rk12
    location: tp-101
    ma:
    own:
  • name: rk14
    location: tp-201
    ma: p11023
    own: p11023
  • name: rk15
    location: tc-332
    ma:
    own: p92032

`

and I want to update nodes.ma with somevalue based on location in playbook , if ma is not defined.
I try lineinfile , but there could be more lines that ma was not defined. (like rk12 , rk15 )
can I update specified nodes.ma in playbook ?

Update vars files based on the content of a variable it contains
sounds like doing things backwards.
Could you tell more about your ACTUAL deployment goal(s)? I.e. what
are you trying to achieve with ansible?

like I said , I want to update nodes.ma with somevalue based on location in playbook , if ma is not defined.
ma is matainer’s id , owner is customer’s id.
with different location , there are different matainers.
and because some reason , we didn’t keep all that records , so there are plenty of missing maintainers
I want to update these data via ansible , if ma is missing , then I will assign a employee to it based on location.
thats what I want to do.

Dick Visser於 2020年5月13日星期三 UTC+8下午3時04分42秒寫道:

like I said , I want to update nodes.ma <http://nodes.ma> with somevalue based on location in playbook , if ma is not
defined.
ma is matainer's id , owner is customer's id.
with different location , there are different matainers.
and because some reason , we didn't keep all that records , so there are plenty of missing maintainers
I want to update these data via ansible , if ma is missing , then I will assign a employee to it based on location.
thats what I want to do.

How does your playbook look like right now?

Regards
        Racke

location is defined in inventory file , but I have trouble to update nodes.pub

`

  • hosts: srvs
    become: yes
    vars:
    location: l13

tasks:

  • name: debug vars
    debug:
    var: nodes

  • name: update vars.yml when pub is not defined
    lineinfile:
    line: “public: none”
    path: vars.yml
    state: present
    when: item.location == location and item.pub == “”
    with_items: “{{ nodes }}”

`

Stefan Hornburg (Racke)於 2020年5月13日星期三 UTC+8下午4時03分16秒寫道:

location is defined in inventory file , but I have trouble to update nodes.pub

lineinfile is not appropriate for any structured data (JSON, YAML, XML, ...).

Regards
        Racke

so , what module you recommend ?

Stefan Hornburg (Racke)於 2020年5月13日星期三 UTC+8下午10時12分58秒寫道: