@@ -98,6 +98,45 @@ ls ~/.ansible/collections/ansible_collections/cisco/catalystcenter/cvp/ | wc -l
9898
9999---
100100
101+ ## 🧾 Prerequisite: Inventory File
102+
103+ Every CVP playbook declares ` hosts: catalyst_center_hosts ` , so an inventory
104+ that defines this group is ** required** . Running ` ansible-playbook ` without
105+ ` -i <inventory> ` will result in ` skipping: no hosts matched ` and no tasks
106+ will execute. Passing ` -e catalystcenter_host=... ` alone is ** not** enough,
107+ because it only sets SDK connection variables, not the Ansible host pattern.
108+
109+ Minimal inventory (` inventory/hosts.yml ` ):
110+
111+ ``` yaml
112+ ---
113+ catalyst_center_hosts :
114+ hosts :
115+ catalyst_center220 :
116+ ansible_host : " {{ lookup('env', 'HOSTIP') }}"
117+ catalystcenter_host : " {{ lookup('env', 'HOSTIP') }}"
118+ catalystcenter_username : " {{ lookup('env', 'CATALYST_CENTER_USERNAME') }}"
119+ catalystcenter_password : " {{ lookup('env', 'CATALYST_CENTER_PASSWORD') }}"
120+ catalystcenter_port : 443
121+ catalystcenter_version : 3.1.5
122+ catalystcenter_verify : false
123+ catalystcenter_debug : false
124+ ` ` `
125+
126+ Export the matching environment variables:
127+
128+ ` ` ` bash
129+ export HOSTIP=<catalyst-center-ip-or-fqdn>
130+ export CATALYST_CENTER_USERNAME=<username>
131+ export CATALYST_CENTER_PASSWORD='<password>'
132+ ```
133+
134+ > All ` ansible-playbook ` examples below assume this inventory exists at
135+ > ` inventory/hosts.yml ` . Per-CVP README files (e.g.
136+ > [ cvp/swim/README.md] ( cvp/swim/README.md ) ) use the same pattern.
137+
138+ ---
139+
101140## 🚀 Quick Start
102141
103142### 5-Minute CVP Example
@@ -121,11 +160,11 @@ cat README.md
121160# 6. Edit variables
122161vi vars/site_hierarchy_design_vars.yml
123162
124- # 7. Run playbook
125- ansible-playbook playbook/site_hierarchy_playbook.yml \
126- -e catalystcenter_host=10.1.1.1 \
127- -e catalystcenter_username=admin \
128- -e catalystcenter_password=secret \
163+ # 7. Run playbook (requires an inventory with the catalyst_center_hosts group;
164+ # see "Prerequisite: Inventory File" above)
165+ ansible-playbook \
166+ -i inventory/hosts.yml \
167+ playbook/site_hierarchy_playbook.yml \
129168 -vvv
130169```
131170
@@ -189,51 +228,58 @@ git init
189228git add .
190229git commit -m " Initial CVP setup"
191230
192- # Run playbooks
193- ansible-playbook site_hierarchy/playbook/site_hierarchy_playbook.yml
194- ansible-playbook device_discovery/playbook/device_discovery_playbook.yml
231+ # Run playbooks (inventory must define the catalyst_center_hosts group)
232+ ansible-playbook -i inventory/hosts.yml \
233+ site_hierarchy/playbook/site_hierarchy_playbook.yml
234+ ansible-playbook -i inventory/hosts.yml \
235+ device_discovery/playbook/device_discovery_playbook.yml
195236```
196237
197238### Pattern 2: Direct Reference (Quick Testing)
198239
199240** Best for** : Testing, one-off runs, CI/CD
200241
201242``` bash
202- # Run CVP directly from collection
243+ # Run CVP directly from collection (still requires an inventory file)
203244ansible-playbook \
245+ -i inventory/hosts.yml \
204246 ~ /.ansible/collections/ansible_collections/cisco/catalystcenter/cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml \
205- -e @my-custom-vars.yml \
206- -e catalystcenter_host=10.1.1.1 \
207- -e catalystcenter_username=admin \
208- -e catalystcenter_password=secret
247+ -e VARS_FILE_PATH=$( pwd) /my-custom-vars.yml
209248```
210249
211250### Pattern 3: Hybrid Approach
212251
213252** Best for** : Combining multiple CVPs
214253
215- ``` bash
216- # Create master playbook
217- cat > deploy-all.yml << EOF
254+ ` import_playbook ` is a top-level directive, not a task. Each entry below is a
255+ separate play that inherits the imported playbook's ` hosts: ` (here:
256+ ` catalyst_center_hosts ` ), so the inventory must define that group. Per-CVP
257+ inputs are passed via the ` vars: ` block as ` VARS_FILE_PATH ` , resolved
258+ ** relative to the imported playbook's directory** (see VARS_FILE_PATH note
259+ in any per-CVP README, e.g. [ cvp/swim/README.md] ( cvp/swim/README.md ) ).
260+
261+ ``` yaml
262+ # deploy-all.yml
218263---
219- - name: Complete Catalyst Center Deployment
220- hosts: localhost
221- gather_facts: false
222-
223- tasks:
224- # Import CVP playbooks
225- - name: Deploy Site Hierarchy
226- ansible.builtin.import_playbook: ~/.ansible/collections/ansible_collections/cisco/catalystcenter/cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml
227-
228- - name: Configure Network Settings
229- ansible.builtin.import_playbook: ~/.ansible/collections/ansible_collections/cisco/catalystcenter/cvp/network_settings/playbook/network_settings_playbook.yml
230-
231- - name: Discover Devices
232- ansible.builtin.import_playbook: ~/.ansible/collections/ansible_collections/cisco/catalystcenter/cvp/device_discovery/playbook/device_discovery_playbook .yml
233- EOF
264+ - name : Deploy Site Hierarchy
265+ ansible.builtin.import_playbook : cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml
266+ vars :
267+ VARS_FILE_PATH : ../vars/site_hierarchy_design_vars.yml
268+
269+ - name : Configure Network Settings
270+ ansible.builtin.import_playbook : cvp/network_settings/playbook/network_settings_playbook.yml
271+ vars :
272+ VARS_FILE_PATH : ../vars/network_settings_vars.yml
273+
274+ - name : Discover Devices
275+ ansible.builtin.import_playbook : cvp/device_discovery/playbook/device_discovery_playbook.yml
276+ vars :
277+ VARS_FILE_PATH : ../vars/device_discovery_vars .yml
278+ ` ` `
234279
235- # Run master playbook
236- ansible-playbook deploy-all.yml
280+ ` ` ` bash
281+ # Run master playbook (inventory must define the catalyst_center_hosts group)
282+ ansible-playbook -i inventory/hosts.yml deploy-all.yml
237283```
238284
239285---
@@ -277,27 +323,25 @@ jobs:
277323
278324 - name : Deploy Site Hierarchy
279325 env :
280- CATALYSTCENTER_HOST : ${{ secrets.CATALYSTCENTER_HOST }}
281- CATALYSTCENTER_USERNAME : ${{ secrets.CATALYSTCENTER_USERNAME }}
282- CATALYSTCENTER_PASSWORD : ${{ secrets.CATALYSTCENTER_PASSWORD }}
326+ HOSTIP : ${{ secrets.CATALYSTCENTER_HOST }}
327+ CATALYST_CENTER_USERNAME : ${{ secrets.CATALYSTCENTER_USERNAME }}
328+ CATALYST_CENTER_PASSWORD : ${{ secrets.CATALYSTCENTER_PASSWORD }}
283329 run : |
284- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml \
285- -e catalystcenter_host=$CATALYSTCENTER_HOST \
286- -e catalystcenter_username=$CATALYSTCENTER_USERNAME \
287- -e catalystcenter_password=$CATALYSTCENTER_PASSWORD \
288- -e @vars/production-sites.yml
330+ ansible-playbook \
331+ -i inventory/hosts.yml \
332+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml \
333+ -e VARS_FILE_PATH=$(pwd)/vars/production-sites.yml
289334
290335 - name : Deploy Network Settings
291336 env :
292- CATALYSTCENTER_HOST : ${{ secrets.CATALYSTCENTER_HOST }}
293- CATALYSTCENTER_USERNAME : ${{ secrets.CATALYSTCENTER_USERNAME }}
294- CATALYSTCENTER_PASSWORD : ${{ secrets.CATALYSTCENTER_PASSWORD }}
337+ HOSTIP : ${{ secrets.CATALYSTCENTER_HOST }}
338+ CATALYST_CENTER_USERNAME : ${{ secrets.CATALYSTCENTER_USERNAME }}
339+ CATALYST_CENTER_PASSWORD : ${{ secrets.CATALYSTCENTER_PASSWORD }}
295340 run : |
296- ansible-playbook cvp/network_settings/playbook/network_settings_playbook.yml \
297- -e catalystcenter_host=$CATALYSTCENTER_HOST \
298- -e catalystcenter_username=$CATALYSTCENTER_USERNAME \
299- -e catalystcenter_password=$CATALYSTCENTER_PASSWORD \
300- -e @vars/production-network-settings.yml
341+ ansible-playbook \
342+ -i inventory/hosts.yml \
343+ cvp/network_settings/playbook/network_settings_playbook.yml \
344+ -e VARS_FILE_PATH=$(pwd)/vars/production-network-settings.yml
301345` ` `
302346
303347### GitLab CI
@@ -336,7 +380,7 @@ validate:
336380 - prepare
337381 script :
338382 - *install_ansible
339- - ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --syntax-check
383+ - ansible-playbook -i inventory/hosts.yml cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --syntax-check
340384 - ansible-lint cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml || true
341385
342386deploy :
@@ -346,11 +390,13 @@ deploy:
346390 - prepare
347391 script :
348392 - *install_ansible
349- - ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml
350- -e catalystcenter_host=$CATALYSTCENTER_HOST
351- -e catalystcenter_username=$CATALYSTCENTER_USERNAME
352- -e catalystcenter_password=$CATALYSTCENTER_PASSWORD
353- -e @vars/production.yml
393+ - export HOSTIP=$CATALYSTCENTER_HOST
394+ - export CATALYST_CENTER_USERNAME=$CATALYSTCENTER_USERNAME
395+ - export CATALYST_CENTER_PASSWORD=$CATALYSTCENTER_PASSWORD
396+ - ansible-playbook
397+ -i inventory/hosts.yml
398+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml
399+ -e VARS_FILE_PATH=$CI_PROJECT_DIR/vars/production.yml
354400 only :
355401 - main
356402 when : manual
@@ -401,7 +447,8 @@ pipeline {
401447 steps {
402448 sh '''
403449 . venv/bin/activate
404- ansible-playbook ${CVP_PATH}/${CVP_NAME}/playbook/*_playbook.yml --syntax-check
450+ ansible-playbook -i inventory/hosts.yml \
451+ ${CVP_PATH}/${CVP_NAME}/playbook/*_playbook.yml --syntax-check
405452 ' ''
406453 }
407454 }
@@ -414,11 +461,13 @@ pipeline {
414461 input message : ' Deploy to production?' , ok: 'Deploy'
415462 sh '''
416463 . venv/bin/activate
417- ansible-playbook ${CVP_PATH}/${CVP_NAME}/playbook/*_playbook.yml \
418- -e catalystcenter_host=$CATALYSTCENTER_HOST \
419- -e catalystcenter_username=$CATALYSTCENTER_USERNAME \
420- -e catalystcenter_password=$CATALYSTCENTER_PASSWORD \
421- -e @vars/${ENVIRONMENT}.yml \
464+ export HOSTIP=$CATALYSTCENTER_HOST
465+ export CATALYST_CENTER_USERNAME=$CATALYSTCENTER_USERNAME
466+ export CATALYST_CENTER_PASSWORD=$CATALYSTCENTER_PASSWORD
467+ ansible-playbook \
468+ -i inventory/hosts.yml \
469+ ${CVP_PATH}/${CVP_NAME}/playbook/*_playbook.yml \
470+ -e VARS_FILE_PATH=${WORKSPACE}/vars/${ENVIRONMENT}.yml \
422471 -vv
423472 ' ''
424473 }
@@ -590,7 +639,8 @@ vault_catalystcenter_username: "admin"
590639vault_catalystcenter_password: "secret"
591640
592641# Reference in playbook
593- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml \
642+ ansible-playbook -i inventory/hosts.yml \
643+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml \
594644 -e catalystcenter_host="{{ vault_catalystcenter_host }}" \
595645 --ask-vault-pass
596646```
@@ -610,13 +660,16 @@ yamale -s cvp/site_hierarchy/schema/sites_schema.yml \
610660
611661```bash
612662# Use check mode
613- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --check
663+ ansible-playbook -i inventory/hosts.yml \
664+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --check
614665
615666# Use diff mode
616- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --diff
667+ ansible-playbook -i inventory/hosts.yml \
668+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --diff
617669
618670# Limit to specific hosts
619- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --limit dev-catalyst-center
671+ ansible-playbook -i inventory/hosts.yml \
672+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --limit dev-catalyst-center
620673```
621674
622675### 5. Keep CVPs Updated
@@ -661,15 +714,24 @@ chmod -R u+rw ~/.ansible/collections/ansible_collections/cisco/catalystcenter/cv
661714
662715```bash
663716# Run with verbose output
664- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml -vvv
717+ ansible-playbook -i inventory/hosts.yml \
718+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml -vvv
665719
666720# Check syntax
667- ansible-playbook cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --syntax-check
721+ ansible-playbook -i inventory/hosts.yml \
722+ cvp/site_hierarchy/playbook/site_hierarchy_playbook.yml --syntax-check
668723
669724# Validate variables
670725cat cvp/site_hierarchy/vars/site_hierarchy_design_vars.yml
671726```
672727
728+ ### `skipping: no hosts matched`
729+
730+ This error means the inventory does not define the `catalyst_center_hosts`
731+ group that every CVP playbook targets. Create the inventory shown in
732+ [Prerequisite: Inventory File](#-prerequisite-inventory-file) and pass it
733+ with `-i`. Setting `-e catalystcenter_host=...` alone will not fix this.
734+
673735---
674736
675737## 📞 Support
0 commit comments