Greetings Created a role in which several groups of hosts with different functionalities are registered in the inventory file. In order not to litter I cite an excerpt from the code:

[elasticsearch] dev-elastic-01 ansible_host=192.168.37.10 [kibana] dev-kibana-01 ansible_host=192.168.37.10 [logstash] dev-logstash-01 ansible_host=192.168.37.15 main.yml - name: Update repositories cache and install {{app.name}} package sudo: yes apt: name: "{{item}}" state: installed update_cache: yes with_items: "{{app.name}}" app.name указан в group_vars(kibana, elastic, logstash) group_vars/elasticsearch app: name: 'elasticsearch' 

In a role I start installation of the program by means of the apt module. If in the inventory file you specify different addresses for hosts, there is no problem, but if you specify the same host address (for example, I want both the frontend and the backend on one host), an error occurs when the file is locked

 Failed to lock apt for exclusive operation 

As far as I understand, due to the fact that the roles are executed in parallel, at one moment there is an appeal to the installer, who is already occupied by another process. How can I start the installation in sequence? Honestly, the ideas are over. Maybe someone faced this problem. Thanks in advance!

    1 answer 1

    Firstly, the role cannot contain an inventory - you have a separate one: the role, playbook and inventory.

    Now, at the core of the issue: the use of different names for the same target server is a hack, which is sometimes used if it does not fit into the standard grouping of variables in the inventory. If you do this and there are conflicting tasks (for example, apt ), the only way out is serial:1 in this node, but this slows down a lot with a large number of hosts.

    Usually for the goal you want to achieve ...

    For example, I want both frontend and backend on one host

    ... use different roles + different groups.

    Those. in your case should be:

    three roles

    1) kibana

    2) elastic

    3) logstash

    4) it is possible that the parameterized base-app role (which the above is called with the app_name parameter)

    inventory with groups

     dev-host1 ansible_host=192.168.37.10 dev-host2 ansible_host=192.168.37.15 [elasticsearch] dev-host1 [kibana] dev-host1 [logstash] dev-host2 

    playbook for applying roles to groups

     - hosts: elasticsearch roles: [elastic] - hosts: kibana roles: [kibana] - hosts: logstash roles: [logstash] 
    • Thank you, Konstantin! The first sign for the installation of the tree was written using different roles, but they were told to write a universal one, well, I redid it. While I was using the docker, there were no problems, but how it was necessary to write for Debian and with the installation of packages such a problem arose. The structure of the project: group_vars: elasticsearch kibana ... roles: -> task -> main.yml -> use_apt.yml A separate inventory file and a separate playbook in which tasks are specified. I also looked towards the serial, but I didn’t really understand it, as it will be slow. Those. Option one is to divide into roles. - THUND3R 5:59 pm