changing root password with an ansible playbook
For starter, I’d remove debug messages: they do nothing except leaking sensitive information. If you want a deeper sense of what is going on when running your playbook, you can always invoke Ansible with the verbose (-v) option.

Second, I would not use vars to store a password. Instead, I would ask it to the user using a vars_prompt. In fact, using a prompt to update a user password seems so common a need that Ansible itself provide this very possibility; but here you want to automatically append something else, so I’d reuse part of your approach.

The playbook I’d use would be:

- hosts: test

  vars_prompt:
    - name: shared_string
    - prompt: "Common base for your passwords? "
    - private: yes

  tasks:
   - name: Extract last digits of remote host ip
     set_fact:
        last_digits: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] | regex_search(regexp) }}"
     vars:
        regexp: '\d{1,3}$'

   - name: Compose and encrypt the password as shared_string@last_digits
     command: openssl passwd -crypt "{{ shared_string }}@{{ last_digits }}"
     register: crypted_password

   - name: Change root password
     user: name=root update_password=always password={{ crypted_password.stdout }}