0
votes

I got a dir structure like this:

.
├── inventories
│   └── production
│       ├── ansible.cfg
│       ├── group_vars
│       │   ├── all.yml
│       │   └── gitlab.yml
│       ├── hosts
│       └── host_vars
│           
├── playbooks
│   └── gitlab.yml
└── roles
    └── gitlab
        ├── defaults
        │   └── main.yml
        ├── handlers
        │   ├── gitlab.yml
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── README.md
        ├── tasks
        │   ├── configure.yml
        │   ├── conf_integrity.yml
        │   ├── hook.yml
        │   ├── install.yml
        │   └── main.yml
        ├── templates
        │   ├── certificates
        │   ├── gitlab.rb.j2
        │   ├── post-receive-gdys.sh.j2
        │   ├── post-receive-mys.sh.j2
        │   ├── post-receive-no-backup-gdys.sh.j2
        │   ├── post-receive-no-backup-mys.sh.j2
        │   ├── post-receive.sh.j2
        │   ├── ssl-crt.j2
        │   └── ssl-key.j2
        └── vars
            ├── conf_list.yml
            ├── hook.yml
            ├── main.yml
            └── package.yml

And I want to import all.yml vars to all of my hosts(in any role) for production inventory. And want to import group/role spesific vars (like gitlab.yml) to only my relevant roles. How can i do this? How should be content of my gitlab.yml playbook? In my setup ansible cant import the group_vars/all.yml to my playbook's tasks.

inventories/production/hosts:

[ansible]

[gitlab]
gitlab.zek.local

inventories/production/group_vars/all.yml:

gitlab_settings:                    
    Fqdn: "git.zek.local"       
    Rails_shell_ssh_port: "22"      
    Use_self_signed_certs: "yes"    
    Backup:
        enabled: "no"
        Server: git02.zek.local
        Port: 22 
ssh_settings: 
    Port: "22"                      
    PasswordAuthentication: "no" 

roles/gitlab/tasks/configure.yml:

- name: Generating ssl cert for GitLab
  command: >
    openssl req -x509 -nodes -subj '/CN={{ gitlab_settings[Fqdn] }}' -days 365
    -newkey rsa:4096 -sha256 -keyout /etc/gitlab/{{ gitlab_settings[Fqdn] }}.key -out /etc/gitlab/ssl/{{ gitlab_settings[Fqdn] }}.crt
    creates=/etc/gitlab/ssl/{{ gitlab_settings[Fqdn] }}.crt
  when: "{{ gitlab_settings['Use_self_signed_certs'] }}" == "yes"
  notify:
    - GitLab servisi yeniden baslatiliyor
  sudo: yes
  tags: ssl

playbooks/gitlab.yml:

---
- hosts: gitlab 
  remote_user: zek
  sudo: yes
  vars_files:
  - ../roles/gitlab/vars/package.yml
  - ../roles/gitlab/vars/hook.yml
  - ../roles/gitlab/vars/conf_list.yml
  roles:
  - { role: gitlab }

my command for run playbook:

ansible-playbook -i inventories/production playbooks/gitlab.yml  --flush-cache
1
Please clean up your duplicated questionmdaniel
I did, sorry happened by mistake.Zekeriya Akgül

1 Answers

0
votes

use a separate inventory:

  • inventory/production
  • inventory/global

In global put your global vars: inventory/global/group_vars/all.yml

Execute your playbook with the two inventories:

ansible-playbook -i inventories/production -i invenrory/global playbooks/gitlab.yml