# set-netbox-tag

This role sets tags on virtual machines in NetBox.

## Requirements

- netbox.netbox collection installed
- NETBOX_API and NETBOX_TOKEN environment variables or variables set

## Role Variables

- `netbox_tags`: List of tags to add to the virtual machine (default: [])

## Available Tags

The following tags are available in your NetBox instance:

- `732` - VM size/identifier
- `TAPI` - TAPI systems
- `ansibleaccess` - Ansible management access enabled
- `automation` - Automated deployment
- `azure-sync` - Azure synchronized
- `EXAMPLE-CORP.COM` - CCTA domain systems
- `DMZ23.EXAMPLE.COM` - DMZ zone 23
- `DMZ.EXAMPLE.COM` - DMZ zone 24
- `itsm` - ITSM managed systems
- `large-vm` - Large virtual machine
- `medium-vm` - Medium virtual machine
- `noansibleaccess` - No Ansible access
- `notinsatellite` - Not in satellite
- `satellite` - Satellite managed
- `small-vm` - Small virtual machine
- `vmware-auto-updated` - VMware auto-updated

To see all available tags, run:

```bash
curl -H "Authorization: Token YOUR_TOKEN" https://netbox.example.EXAMPLE-CORP.COM/api/extras/tags/ -k | jq '.results[] | {name, slug}'
```

## Example Playbook

```yaml
- hosts: servers
  roles:
    - role: set-netbox-tag
```

### Usage with NetBox inventory and limit:

```bash
# Set environment variable for NetBox token
export NETBOX_TOKEN="your-netbox-api-token"

# Add tags to specific hosts (with vault password for inventory)
ansible-playbook set-netbox-tags.yml -i netbox.yml --limit "hostname.EXAMPLE-CORP.COM" -e '{"netbox_tags":["satellite","EXAMPLE-CORP.COM"]}' --ask-vault-pass

# Add tags to multiple hosts
ansible-playbook set-netbox-tags.yml -i netbox.yml --limit "*.EXAMPLE-CORP.COM" -e '{"netbox_tags":["production"]}' --ask-vault-pass
```

**Note:** Use JSON format `-e '{"netbox_tags":["tag1","tag2"]}'` to pass the tags list properly.

## License

GPL-2.0-or-later
