Join two variables and store in new variable in playbook

I want to join two variables in ansible playbook to store in another variable to use it further in the code.

I tried as below, but encountering errors

  • debug: msg = “{{ ver1 ~ ver2 }}”
    set_fact:
    version{{msg}}

ERROR! conflicting action statements (debug, set_fact)

The error appears to have been in ‘/home/devOps/upgradeTeradata/shruthi.yml’: line 63, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- debug: msg = “value is {{ ver1 ~ ver2 }}”

  • debug: msg = “{{ ver1 ~ ver2 }}”
    ^ here
    We could be wrong, but this one looks like it might be an issue with
    missing quotes. Always quote template expression brackets when they
    start a value. For instance:

with_items:

  • {{ foo }}

Should be written as:

with_items:

  • “{{ foo }}”

please help…

You can only have one module in one task. Debug is a module and set_fact is a module.
Debug is just for printing test to the console of the user running the play/playbook.

When using Ansible style YAML you can't have spaces in front or after the equal sign.
So your debug need to be written like this

- debug: msg="{{ ver1 ~ ver2 }}"

The msg in debug is not a variable, it's a parameter to debug to specify what message you would like to print out to the user.

set_fact must be it own task, all task start with a dash.

- set_fact:
     version: '{{ ver1 ~ ver2 }}'

or

- set_fact:
     version: '{{ ver1 }}{{ ver2 }}'

Then you can print out this version variable with debug like so

- debug: msg="The version is {{ version }}"

or

- debug: var=version

Thankyou so much for explaining me so patiently. Am new to ansible.