Q:

Can we use a variable for two main.yml which are different foler of same repo

In Azure Repos I have two main.yml in different folders . One of main.yml is installing list of packages and another is validating those packages installed or not. Everytime I add a new package to be installed. I need to add the same in another yaml. Is there any way that When I update the package name in one yaml that will be applicable or taken to another yaml aswell.
I cant merge both of them as Am using for different pipelines.
#This is one main.yml
- name: install basic packages
  action: >
    {{ ansible_pkg_mgr }} name={{ item }} state=present update_cache=yes
  with_items:
    - vim
    - tmux
    - mosh
#This is another
- name:Check for packages
  shell: rpm vim tmux mosh
  register: packages_status

A:

Q: "Can we use a variable for two main.yml which are in different folders of the same repo?"

A: This can be accomplished by a variable declared on any precedence level. The details depend on what hosts or what groups of hosts will use this variable. See Variable precedence: Where should I put a variable?. For example, let's take a simple case with one host test_01 and list of the packages pkg_list declared in the host_vars.
shell> cat hosts
test_01

shell> cat host_vars/test_01 
pkg_list: [vim, tmux, mosh]

The playbook below includes two roles to install and validate the packages
shell> cat pb.yml
- hosts: test_01
  tasks:
    - include_role:
        name: install
        tasks_from: main.yml
    - include_role:
        name: validate
        tasks_from: main.yml

shell> cat roles/install/tasks/main.yml
- debug:
    msg: install {{ pkg_list }}

shell> cat roles/validate/tasks/main.yml
- debug:
    msg: validate {{ pkg_list }}

gives
shell> ansible-playbook -i hosts pb.yml

PLAY [test_01] ****

TASK [include_role : install] ****
TASK [install : debug] ****
ok: [test_01] => 
  msg: install ['vim', 'tmux', 'mosh']

TASK [include_role : validate] ****
TASK [validate : debug] ****
ok: [test_01] => 
  msg: validate ['vim', 'tmux', 'mosh']

