In the vlan case, you are assuming vlan interface names are vlan* but it's not true, it can be ethX.vlanID, .... and if you test the code get error message that config device not exists. that is the config vlan file listed in ls.