# Packer variable declaration issue

**URL:** <https://discuss.hashicorp.com/t/packer-variable-declaration-issue/52783>\
**Category:** Packer\
**Created:** [April 17, 2023, 9:25am UTC](https://discuss.hashicorp.com/t/packer-variable-declaration-issue/52783 "2023-04-17T09:25:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prakash.prks](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@prakash.prks](https://discuss.hashicorp.com/u/prakash.prks)\
**Post date:** [April 17, 2023, 9:25am UTC](https://discuss.hashicorp.com/t/packer-variable-declaration-issue/52783/1 "2023-04-17T09:25:26Z")

</div>

Hi,

I’m trying to use packer using ansible playbook. I need to pass the variable to packer code via playbook so Im passing through extra arguments like below:

command: “packer build -var ‘parameter1=test’ -var ‘parameter2=test2’ myfile.hcl”

Now How I need to use it inside the myfile.hcl with these variable names.

When I try to use “{{ user `parameter1` }}” getting error saying:

_variable was passed in the command line but was not found in_  
_known variables. To declare variable “parameter1”, place this block in one of_  
_your .pkr files, such as variables.pkr.hcl_

Please help me on this.

---

<div class="post-metadata">

**Author:** ![motorbass](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/motorbass/32/33190_2.png) [@motorbass](https://discuss.hashicorp.com/u/motorbass)\
**Post date:** [April 18, 2023, 7:04pm UTC](https://discuss.hashicorp.com/t/packer-variable-declaration-issue/52783/2 "2023-04-18T19:04:57Z")

</div>

The error log says it all, just create a variable into your variable file, and set a default value, then when you pass it from Ansible to Packer, variable will exist and be overwritten by your value (else it will have default value you set)

Something like this :

```auto
variable "flavor" {
  type = string
  default = "strawberry"
}

```

---

<div class="post-metadata">

**Author:** ![prakash.prks](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@prakash.prks](https://discuss.hashicorp.com/u/prakash.prks)\
**Post date:** [April 19, 2023, 5:45am UTC](https://discuss.hashicorp.com/t/packer-variable-declaration-issue/52783/3 "2023-04-19T05:45:51Z")

</div>

thanks for your reply
