how to dynamic update value in vars_file

32 views
Skip to first unread message

Eric Chang

unread,
May 12, 2020, 9:34:12 PM5/12/20
to Ansible Project
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 ?

Dick Visser

unread,
May 13, 2020, 3:04:42 AM5/13/20
to ansible...@googlegroups.com
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?
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/adc79238-ee69-4883-86e0-e6555b9a5356%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Eric Chang

unread,
May 13, 2020, 3:32:04 AM5/13/20
to Ansible Project
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秒寫道:
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?

On Wed, 13 May 2020 at 03:34, Eric Chang <chan...@gmail.com> wrote:
>
> 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 ?
>



--

Stefan Hornburg (Racke)

unread,
May 13, 2020, 4:03:16 AM5/13/20
to ansible...@googlegroups.com
On 5/13/20 9:32 AM, Eric Chang wrote:
> 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

>
>
> Dick Visser於 2020年5月13日星期三 UTC+8下午3時04分42秒寫道:
>
> 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?
>
> On Wed, 13 May 2020 at 03:34, Eric Chang <chan...@gmail.com <javascript:>> wrote:
> >
> > 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 <http://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 <http://nodes.ma> in playbook ?
> >
>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Eric Chang

unread,
May 13, 2020, 9:58:35 AM5/13/20
to Ansible Project
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秒寫道:

Stefan Hornburg (Racke)

unread,
May 13, 2020, 10:12:58 AM5/13/20
to ansible...@googlegroups.com
On 5/13/20 3:58 PM, Eric Chang wrote:
> 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


> |
> - hosts: srvs
>   become: yes
>   vars:
>     location: l13
>
>   tasks:                     
>     -name:debug vars        
>       debug:                 
>         var:nodes            
>                              
>     -name:update vars.yml whenpub isnotdefined
>       lineinfile:           
>         line:"public: none" 
>         path:vars.yml        
>         state:present        
>       when:item.location ==location anditem.pub ==""   
>       with_items:"{{ nodes }}"
>
>
> |
>
>
> Stefan Hornburg (Racke)於 2020年5月13日星期三 UTC+8下午4時03分16秒寫道:
>
> On 5/13/20 9:32 AM, Eric Chang wrote:
> > like I said , I want to update nodes.ma <http://nodes.ma> <http://nodes.ma> with somevalue based on location in
> >     > and I want to update nodes.ma <http://nodes.ma> <http://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 <http://nodes.ma> <http://nodes.ma> in playbook ?
> >     >
> >
> >
> >
> >     --
> >     Dick Visser
> >     Trust & Identity Service Operations Manager
> >     GÉANT
> >
> > --
> > 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
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/dd9ece05-dfdb-4bc5-9a83-0840789bf1a5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/dd9ece05-dfdb-4bc5-9a83-0840789bf1a5%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Eric Chang

unread,
May 14, 2020, 9:30:46 AM5/14/20
to Ansible Project
so , what module you recommend ?

Stefan Hornburg (Racke)於 2020年5月13日星期三 UTC+8下午10時12分58秒寫道:
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/d1aba12f-0f26-4b5b-8c83-c45d542553e0%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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
Reply all
Reply to author
Forward
0 new messages