# Is it possible to change config value through leafref?

**URL:** <https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007>\
**Category:** YANG\
**Created:** [February 22, 2022, 5:57pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007 "2022-02-22T17:57:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ypopov](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@ypopov](https://dmap-community.ductus.global/u/ypopov)\
**Post date:** [February 22, 2022, 5:57pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007/1 "2022-02-22T17:57:56Z")

</div>

I have the following model

```
   container system1 {
     leaf system-name {
         type string;
         default "";
       }
  }
  container system3 {
      leaf system1Name {
          type leafref {
              path "/system1/system-name";
          }
      }
  }

```

If I try to set systems-name through leafref it fails:

```
    ubuntudsk1(config)# 
    ubuntudsk1(config)# system3 system1Name Linux
    ubuntudsk1(config)# commit
    Aborted: illegal reference 'system3 system1Name'
    ubuntudsk1(config)# 

```

is this supposed to work like this?

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [February 22, 2022, 7:49pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007/2 "2022-02-22T19:49:36Z")

</div>

Assuming you don’t have any other commands/config written prior to the ones in your comment, yes…

By [RFC definition](https://datatracker.ietf.org/doc/html/rfc7950#section-9.9), `leafref` is a “reference” to an item existing at the specified path (`/system1/system-name` in your case).  
You don’t show any such command creating `Linux` in `system1 system-name`, so ConfD correctly rejects configuration as invalid - reference does not point to existing item…

---

<div class="post-metadata">

**Author:** ![ypopov](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@ypopov](https://dmap-community.ductus.global/u/ypopov)\
**Post date:** [February 22, 2022, 8:11pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007/3 "2022-02-22T20:11:12Z")

</div>

The item has default value, so technically it should exist.  
But even if I do the following it complains:

```
    ubuntudsk1(config)# system1 system-name Windows
    ubuntudsk1(config)# commit
    Aborted: illegal reference 'system3 system1Name'
    ubuntudsk1(config)# 

```

So, what’s wrong?

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [February 22, 2022, 8:37pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007/4 "2022-02-22T20:37:40Z")

</div>

but default value shown in your excerpt is `""` - empty string, and not “Linux” or “Windows” that you try to set as reference… `type leafref` means that it can hold values that do exist someplace else - on the path specified…

(leafref it is not a trigger that changes a node that path points to, but reads/validates against it)

```nohighlight
xubuntu-dev(config)# system3 system1Name Linux
xubuntu-dev(config)# commit
Aborted: illegal reference 'system3 system1Name'
xubuntu-dev(config)# system1 system-name Linux
xubuntu-dev(config)# commit
Commit complete.

```

---

<div class="post-metadata">

**Author:** ![ypopov](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@ypopov](https://dmap-community.ductus.global/u/ypopov)\
**Post date:** [February 22, 2022, 8:51pm UTC](https://dmap-community.ductus.global/t/is-it-possible-to-change-config-value-through-leafref/4007/5 "2022-02-22T20:51:38Z")

</div>

OK, thank you.  
I guess I didn’t understand leafref correctly
