D
D
DenZel2020-02-16 15:15:29
linux
DenZel, 2020-02-16 15:15:29

How to automate the value generation process for Ansible?

Hello!
Faced the issue of fully automating the server deployment process using ansible.
On each server I use different variable values: ssh port number, grub password, usernames, their passwords, and a number of other various data.
Tell me, is there any ready-made solution for generating such values ​​(a number, an arbitrary set of characters), the use of which will generate the necessary values ​​​​of variables for var ansible, and which I will later use in templates and other modules.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-02-16
@gen4_gdm

To generate a password (or any other parameter) use lookup, here is an example of user generation with automatic password generation

- 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 password file that will be created later in / tmp I then use to make a letter that I will send to the customer by mail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question