I
I
Ilya Rodionov2019-05-20 11:36:12
ubuntu
Ilya Rodionov, 2019-05-20 11:36:12

Best practice in writing Ansible Playbook?

Colleagues, hello.
I started writing playbooks with ansible, I have a couple of questions about best practice in writing playbooks.
1. I have a 250-line playbook (small, yes), but now I look at other people's playbooks and see that colleagues create roles instead of one continuous text. How do you think it should be done? For example, I will show my part of the playbook:

- name: STAGE 0.0.8 - Install prerequisites
      apt:     
        name: "{{items}}"
        #update_cache: yes
      vars:
        items:
          - apt-transport-https
          - ca-certificates
          - curl
          - software-properties-common
          - net-tools
    - name: STAGE 0.0.9 - Set swap to 1 value
      sysctl:
        name: vm.swappiness
        value: 1
        state: present          
  # ---------    
    - name: STAGE 0.1 - Add the user '' with a primary group of 'sudo and admin'
      user:
        name: r
        shell: /bin/bash
        groups: 
          - sudo 
        state: present
        password: '6$$.'
        createhome: yes

That is, it is logical to put STAGE 0.0* and STAGE 1.* into different roles, or is it a matter of my personal perception? And this is "not necessary"
2. What is the best thing to do if I have different conditions in playbooks for a different group of hosts? That is: for example, hosts in one segment must execute STAGE 5*, but not in another. Is it possible to do this via "flags" at startup. Those. I understand that now all hosts will go from one segment - I use the --segment1 flag, and from the other - --segment2, which bypasses the fifth stage.
2.1 Or is it possible to display something like "yes if procced no if continue" in the console when the fifth stage arrives, which will simply "step over" stage 5
2.2 Or even have your own playbook for your host group? For example, under one - playbook1 with stage5,
3. How to deal with hosts: at the beginning of the playbook. Each time to replace, on which group of hosts to execute the playbook?
4. Bonus. And why are they drowning for salt instead of ansible? What are their fundamental differences and what is better to use for what?
Thanks a lot for the replies!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Shitskov, 2019-05-20
@Zarom

Best practices

  1. If your playbook is not a monolith, you plan to reuse it on many different hosts and playbooks - split it into independent roles
  2. For different groups of hosts, it is better to use a separate playbook, consisting of imports of other playbooks and roles
  3. No way. Each group of hosts has its own playbook.
  4. ??? Who is drowning? Whom?

A
Andrey Tokmakov, 2017-05-18
@minaev007

Add float: left; to the .inner1 block and the blocks will stand up normally

I
iBird Rose, 2017-05-18
@iiiBird

https://jsfiddle.net/e78nuwrk/1/
vertical-align: top;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question