Ansible-role-nginx-config: 정리 μ ˆμ°¨κ°€ μ •λ¦¬λ˜μ§€ μ•ŠμŒ

에 λ§Œλ“  2021λ…„ 03μ›” 23일  Β·  10μ½”λ©˜νŠΈ  Β·  좜처: nginxinc/ansible-role-nginx-config

버그 μ„€λͺ…

conf.d/*.conf 정리λ₯Ό νŠΈλ¦¬κ±°ν•΄μ•Ό ν•˜λŠ” μ½”λ“œκ°€ μ •λ¦¬λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

μž¬ν˜„ν•˜λ‹€

λ™μž‘μ„ μž¬ν˜„ν•˜λŠ” 단계:

nginx_config_cleanup     : '{{ my_cleanup }}'

    # this clean up only happens if the above variable is true
    nginx_config_cleanup_paths:
      - directory:
          - /etc/nginx/conf.d
        recurse: false
    nginx_config_cleanup_files:
      - /etc/nginx/conf.d/default.conf
TASK [nginxinc.nginx_config : Find NGINX config files] ************************************************************************************************************************************************************************************************************************
ok: [testing-snap05.MYDOMAIN.TLD] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': False}) => {"ansible_loop_var": "item", "changed": false, "examined": 13, "files": [{"atime": 1616512425.5879788, "ctime": 1616512425.0159645, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652034, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616512424.6879563, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLDX.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 508, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1616511920.0872648, "ctime": 1616511919.343246, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652037, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616511918.9712367, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 507, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1616512481.8013923, "ctime": 1616512481.229378, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652039, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616512480.8773692, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLDZ.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 508, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1616512450.800613, "ctime": 1616512450.1845973, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652038, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616512449.8325884, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLDY.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 508, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}], "item": {"directory": ["/etc/nginx/conf.d"], "recurse": false}, "matched": 4, "msg": ""}                                                                                                                                                                                          

TASK [nginxinc.nginx_config : Remove NGINX config files] **********************************************************************************************************************************************************************************************************************
ok: [testing-snap05.MYDOMAIN.TLD] => (item=/etc/nginx/conf.d/default.conf) => {"ansible_loop_var": "item", "changed": false, "item": "/etc/nginx/conf.d/default.conf", "path": "/etc/nginx/conf.d/default.conf", "state": "absent"}

μ˜ˆμƒλ˜λŠ” 행동

μƒˆ νŒŒλ¦¬κ°€ μƒμ„±λ˜κΈ° 전에 /etc/nginx/conf.d/*.confκ°€ μ‚­μ œλ  κ²ƒμœΌλ‘œ μ˜ˆμƒν–ˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ default.conf만 μ‚­μ œλ©λ‹ˆλ‹€.

κ·€ν•˜μ˜ ν™˜κ²½:

μžμ‹μ˜ κ°€λŠ₯ν•œ μ—­ν•  nginx-config
nginxinc.nginx, 0.19.1
μ•€μ„œλΈ”: 2.9.6+dfsg-1
μš°λΆ„νˆ¬ 20.04

λͺ¨λ“  10 λŒ“κΈ€

쒋은 캐치. ν…ŒμŠ€νŠΈμ—μ„œλŠ” default.conf 이 μ‚­μ œλœ 것 μ™Έμ—λŠ” 아무 것도 κ³ λ €ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. λ“€μ–΄μ˜€λŠ” PR은 이 버그λ₯Ό ν•΄κ²°ν•˜κ³  μ •λ¦¬λ˜λŠ” 전체 디렉토리에 λŒ€ν•œ μ μ ˆν•œ ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€λ₯Ό μΆ”κ°€ν•΄μ•Ό ν•©λ‹ˆλ‹€.

git pull 후에도 μ—¬μ „νžˆ μ •λ¦¬λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. default.conf만 μ •λ¦¬ν•©λ‹ˆλ‹€. true 및 false둜 μ„€μ •λœ μž¬κ·€λ₯Ό μ‹œλ„ν–ˆμŠ΅λ‹ˆλ‹€.

(item=/etc/nginx/conf.d/default.conf) => {"ansible_loop_var": "item", "changed": false, "item": "/etc/nginx/conf.d/default.conf", "path": "/etc/nginx/conf.d/default.conf", "state": "absent"}

Jinja2 μ—…λ°μ΄νŠΈ 후에도 정리가 μ—¬μ „νžˆ μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 이거 λ‹€μ‹œ μ—΄μ–΄λ³ΌκΉŒμš”?

TASK [nginxinc.nginx_config : Find NGINX config files] ************************************************************************************************************************************************************************************************************************
ok: [testing-snap05.MYDOMAIN.TLD] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': True}) => {"ansible_loop_var": "item", "changed": false, "examined": 7, "files": [{"atime": 1616759901.1814494, "ctime": 1616759896.8093383, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652060, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616759896.5933328, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD_adhoc.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 2, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1616777440.7914264, "ctime": 1616777440.3514154, "dev": 64780, "gid": 0, "gr_name": "root", "inode": 652158, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1616777440.13941, "nlink": 1, "path": "/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 1255, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}], "item": {"directory": ["/etc/nginx/conf.d"], "recurse": true}, "matched": 2, "msg": ""}                                                                                                                                                                                                                                        

TASK [nginxinc.nginx_config : Remove NGINX config files] **********************************************************************************************************************************************************************************************************************

μƒˆλ‘œμš΄ ν…ŒμŠ€νŠΈκ°€ ν†΅κ³Όλ˜κ³  μžˆμœΌλ―€λ‘œ 이것이 μ—­ν• μ˜ 버그인지 μ™„μ „νžˆ ν™•μ‹ ν•  수 μ—†μŠ΅λ‹ˆλ‹€. λ˜ν•œ κ·€ν•˜μ˜ μ˜ˆμ™€ λ™μΌν•œ 파일 이름을 μ‚¬μš©ν•΄ λ³΄μ•˜μ§€λ§Œ μ˜¬λ°”λ₯΄κ²Œ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.


λΆ„μž ν…ŒμŠ€νŠΈ

TASK [ansible-role-nginx-config : Find NGINX config files] *********************
ok: [ubuntu-bionic] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': False})
ok: [centos-7] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': False})
ok: [debian-buster] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': False})
ok: [alpine-3.10] => (item={'directory': ['/etc/nginx/conf.d'], 'recurse': False})

TASK [ansible-role-nginx-config : Remove NGINX config files] *******************
changed: [centos-7] => (item=/etc/nginx/conf.d/default.conf)
changed: [debian-buster] => (item=/etc/nginx/conf.d/default.conf)
changed: [alpine-3.10] => (item=/etc/nginx/conf.d/default.conf)
changed: [ubuntu-bionic] => (item=/etc/nginx/conf.d/default.conf)
changed: [centos-7] => (item=/etc/nginx/conf.d/mock.conf)
changed: [debian-buster] => (item=/etc/nginx/conf.d/mock.conf)
changed: [alpine-3.10] => (item=/etc/nginx/conf.d/mock.conf)
changed: [ubuntu-bionic] => (item=/etc/nginx/conf.d/mock.conf)
changed: [centos-7] => (item=/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf)
changed: [ubuntu-bionic] => (item=/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf)
changed: [debian-buster] => (item=/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf)
changed: [alpine-3.10] => (item=/etc/nginx/conf.d/testing-snap05.staging.MYDOMAIN.TLD.conf)
ok: [centos-7] => (item=/etc/nginx/conf.d/default.conf)
ok: [ubuntu-bionic] => (item=/etc/nginx/conf.d/default.conf)
ok: [debian-buster] => (item=/etc/nginx/conf.d/default.conf)
ok: [alpine-3.10] => (item=/etc/nginx/conf.d/default.conf)

μ΅œμ‹  Ansible 릴리슀둜 μ—…λ°μ΄νŠΈν•΄ λ³΄μ…¨μŠ΅λ‹ˆκΉŒ? λ°°ν›„μ—μ„œ μ‚¬μš©λ˜λŠ” λͺ¨λ“ˆμ€ Ansible 2.9.6 μ΄ν›„λ‘œ μ—…λ°μ΄νŠΈλ˜μ—ˆμ„ 수 μžˆμŠ΅λ‹ˆλ‹€. (μš”μ¦˜ μ‚¬μš©ν•΄μ•Ό ν•˜λŠ” μ ˆλŒ€ μ΅œμ†Œ Ansible λ¦΄λ¦¬μŠ€λŠ” Ansible μ»¬λ ‰μ…˜μ˜ κΈ°λ³Έ μ§€μ›μœΌλ‘œ 인해 2.9.10 μž…λ‹ˆλ‹€.)

Ubuntu 20.04인 μ΅œμ‹  Ubuntu LTS에 μ‚¬μš©ν•  수 μžˆλŠ” μ΅œμ‹  버전인 Ansible 2.9.6이 μžˆμŠ΅λ‹ˆλ‹€.

pip λ˜λŠ” Ansible의 νŒ¨ν‚€μ§€ μ €μž₯μ†Œ https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing -ansible-on-ubuntuλ₯Ό μ‚¬μš©ν•˜μ—¬ μ΅œμ‹  릴리슀λ₯Ό μ„€μΉ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 그렇지 μ•ŠμœΌλ©΄ 일반적으둜 이상적이지 μ•Šμ€ Ubuntu의 νŒ¨ν‚€μ§€ λ¦¬ν¬μ§€ν† λ¦¬μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” μ΅œμ‹  릴리슀λ₯Ό μ‚¬μš©ν•˜κ²Œ λ©λ‹ˆλ‹€.

λ‚΄μ—μ„œλ„μ΄ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. brew μ—μ„œ μ‚¬μš© κ°€λŠ₯ν•œ μ΅œμ‹  ν•­λͺ©:

 > ansible --version
ansible [core 2.11.3]

λ””λ²„κ·Έλ‘œ

  register: nginx_config_files

- debug:
    msg: "{{ nginx_config_files.files  }}"

- name: Remove NGINX config files

λ‚˜λŠ” 점점

TASK [nginxinc.nginx_config : Find NGINX config files] *********************************************************************************
ok: [ansible-test] => (item={'directory': ['/etc/nginx/conf.d', '/etc/nginx/snippets'], 'recurse': True})

TASK [nginxinc.nginx_config : debug] ***************************************************************************************************
fatal: [ansible-test]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'files'\n\nThe error appears to be in '...../roles/nginxinc.nginx_config/tasks/config/cleanup-config.yml': line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n  ^ here\n"}

이전 μ˜κ²¬μ—μ„œ μ–ΈκΈ‰ν–ˆλ“―μ΄ ν˜„μž¬ 이 μ‚¬μš© 사둀에 λŒ€ν•œ λͺ…μ‹œμ  ν…ŒμŠ€νŠΈκ°€ 있으며 λͺ¨λ‘ ν†΅κ³Όν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€(https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/cleanup_module/ converge.yml). μ—¬μ „νžˆ 역할을 μ‹€νŒ¨ν•˜κ²Œ λ§Œλ“œλŠ” 일뢀 극단적인 κ²½μš°κ°€ μžˆμ„ 수 μžˆμ§€λ§Œ 직접 μž¬ν˜„ν•˜λ €λ©΄ 더 μžμ„Έν•œ 정보가 ν•„μš”ν•©λ‹ˆλ‹€. μž‘μ—… 좜λ ₯이 주어지면 λ¬Έμ œλŠ” recurse ν‚€μ›Œλ“œκ°€ ν•΄λ‹Ή ν•­λͺ© μ™ΈλΆ€κ°€ μ•„λ‹ˆλΌ 각 디렉토리 사전 ν•­λͺ©μ— μ†ν•œλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€(μžμ„Έν•œ λ‚΄μš©μ€ 이전에 λ§ν¬ν•œ Molecule ν…ŒμŠ€νŠΈ 확인).

μΆ”μ‹ : nginx_config_files.files λŠ” μ‚¬μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€(https://github.com/nginxinc/ansible-role-nginx-config/blob/main/tasks/config/cleanup-config.yml#L11-L17) πŸ˜„

@alessfg 예, μ‹€μ œλ‘œ 방금 μ°Ύμ•˜μŠ΅λ‹ˆλ‹€. λ‚΄ μ†”λ£¨μ…˜μ— λŒ€ν•΄ 글을 μ“°λ €λ©΄ μ—¬κΈ°λ‘œ μ˜€μ„Έμš” :)
λ¬Έμ œλŠ” Galaxy에 κ²Œμ‹œλœ μ΅œμ‹  릴리슀(λ‚΄ ν”Œλ ˆμ΄λΆμ— μ‚¬μš©)에 0.3.3 버전이 ν¬ν•¨λ˜μ–΄ μžˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. μž‘μ„±ν•œ μ΄λŸ¬ν•œ λ³€κ²½ 사항은 이 νƒœκ·Έμ—λŠ” μ—†μœΌλ©° main μ—λ§Œ μžˆμŠ΅λ‹ˆλ‹€. κ·Έλž˜μ„œ μ €λŠ” requirements.yml을 μœ„ν•΄ μ†ŒμŠ€λ₯Ό git μ €μž₯μ†Œλ‘œ μ „ν™˜ν–ˆμŠ΅λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰