How to automate the process of generating values for Ansible?

Hello!
Faced with the question of full automation of the deployment process of a server using ansible.
On every server I use different variable values: port number the ssh password on grub, user names, their passwords, and a number of other different data.
Tell me, is there any ready solution to generate such values (a number, a random set of characters) that will generate the desired values of the variables for var ansible, and that in the future I will use in templates and other modules.
Thank you!
April 7th 20 at 15:18
1 answer
April 7th 20 at 15:20
Solution
To generate a password (or any other parameter), use the lookup, here is an example of generating the user with automatic generation of password
- name: create users
user:
 name: "{{ item }}"
 createhome: yes
 state: present
 password: "{{ lookup('password', '/tmp/' + ansible_host + '_' + item + '_password.txt encrypt=md5_crypt chars=ascii_letters,digits, length=1
 update_password: on_create
with_items:
 - "{{ users }}"
 register: newuser

The file with a password which after you is created in /tmp I then use to make a letter that will be sent to the customer on mail
It turns out the whole playbook used to create the password?
And tell me how best to implement the generation of values in the file which would be with the following content :
ssh_remote=4322
Password_user=134462dfswq
And so on.
To further take values from it to create the config files for the template - Adonis7 commented on April 7th 20 at 15:23
With the help of templates.
https://docs.ansible.com/ansible/latest/user_guide... - dasia_Kirl commented on April 7th 20 at 15:26

Find more questions by tags AnsibleDevOpsLinux