TASK [Running Windows Update] **********************************************************************************************************
task path: /root/ansible/dhsa/winu.yml:5
win_updates: running win_updates module
Using module file /usr/lib/python2.7/site-packages/ansible/modules/windows/win_updates.ps1
<123.123.123.123> ESTABLISH WINRM CONNECTION FOR USER: test01 on PORT 5986 TO 123.123.123.123 
EXEC (via pipeline wrapper)
The full traceback is:
Exception calling "RunAsUser" with "7" argument(s): "Failed to start become pro
cess (The service cannot be started, either because it is disabled or because i
t has no enabled devices associated with it, Win32ErrorCode 1058)"
At line:907 char:9
+         $result = [AnsibleBecome.BecomeUtil]::RunAsUser($username, $password,
 $l ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception
 

fatal: [123.123.123.123  ]: FAILED! => {
    "changed": false, 
    "msg": "Failed to become user SYSTEM: Exception calling \"RunAsUser\" with \"7\" argument(s): \"Failed to start become process (The service cannot be started, either because it is disabled or because it has no enabled devices associated with it, Win32ErrorCode 1058)\""
}
        to retry, use: --limit @/root/ansible/dhsa/winu.retry

PLAY RECAP *****************************************************************************************************************************
123.123.123.123       : ok=0    changed=0    unreachable=0    failed=1    skipped=0  

 

 

윈도우 보안업데이트 하려고 하는데 위와같이 에러 발생

 

이럴경우에는 윈도우 서비스중 secondary logon  서비스가 사용안함으로 돼 있을경우 에러가 난다. 원래는 윈도우 보안업데이트 실행시 이게 종료돼있어도 자동으로 실행되야하는데 아에 사용안함으로 돼 있으니까 에러 난다.

 

secondary logon 이게 원래 디폴트는 사용안함이 아니다. 근데 보안상 취약한 서비스라 사용안함을 권고하고 있다. 

 

대부분 서비스 사용중이라 이런 에러 자체가 없어서 찾느라 드럽게 힘들었다. 

'job > ansible' 카테고리의 다른 글

ansible git으로 받은 awx 설치시 에러  (1) 2019.07.10
windows host에서 ansible 실행하는법  (0) 2019.05.23
ansible 공부한 모듈들 정리  (0) 2019.05.02
ansible - 디렉토리 구조  (0) 2019.05.02
ansible- error  (0) 2019.04.26

리눅스 서버는 ssh를 통해서 ansible이 통신하는데 윈도우 서버는 winrm 이라는 윈도우 리모트 매니져를 통한다.

winrm 은 윈2012 는 기본적으로 실행이 돼 있다. 5985 포트로 올라와있음

근데 ansible은 기본적으로 winrm의 ssl 5986 포트를 통해서 통신을 해야 한다.(5985로도 할 수는 있는데 보안 뭐 실행안되고 뭐 그런게 있는듯)

 

 

[root@master ~]# ansible -i /etc/ansible/hosts win -m win_ping
123.123.123.123 | UNREACHABLE! => {
    "changed": false, 
    "msg": "ssl: HTTPSConnectionPool(host='123.123.123.123', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(, 'Connection to 123.123.123.123 timed out. (connect timeout=30)'))", 
    "unreachable": true
}

 

위와같이 에러가 나는 이유는 windows hosts 서버에 winrm 5986 포트 리슨이 안돼있어서(즉 winrm ssl 실행이 안돼있어서) 이다.

 

 

그전에 winrm no module 없다고 뜨면

pip pywinrm 으로 pywinrm 설치해줘야 한다.

 

windows 2012 의 경우 파워쉘 실행후
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"

$file = "$env:temp\ConfigureRemotingForAnsible.ps1"

(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)

powershell.exe -ExecutionPolicy ByPass -File $file

 

 

위와 같이 실행

 

위 구문을 실행하면 된다.

 

[root@master ~]# ansible -i /etc/ansible/hosts win -m win_ping
123.123.123.123 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

잘된다.

 

hosts 파일 내용은

[win]
123.123.123.123 
[win:vars]
ansible_password='123123123'
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_user=administrator
ansible_port=5986

'job > ansible' 카테고리의 다른 글

ansible git으로 받은 awx 설치시 에러  (1) 2019.07.10
ansible - windows Win32ErrorCode 1058  (0) 2019.05.23
ansible 공부한 모듈들 정리  (0) 2019.05.02
ansible - 디렉토리 구조  (0) 2019.05.02
ansible- error  (0) 2019.04.26

 maxminddb 라는걸로 올릴 수 있는데 그거 하려면 뭐 gcc 랑 c++ 버전 이런게 centos 5버전에는 안맞는 버전들이다.

어쨋든 centos5 버전은 아래와 같이 하면 된다.

 

 

https://dev.maxmind.com/geoip/legacy/mod_geoip2/ 참고

 

GeoIP Legacy Apache Module « MaxMind Developer Site

GeoIP Legacy Apache Module New Apache Module Available: This module is for the GeoIP Legacy format (dat). To read the MaxMind DB format (mmdb) used by GeoIP2, please see mod_maxminddb Description The mod_geoip2 module embeds GeoIP Legacy database lookups i

dev.maxmind.com

 

설치순서는 대략적으로

1.geoip를 서버에 설치하고

2.geoip의 데이터를 넣어주고

3.설치된 geoip를 가지고 아파치용 geoip 모듈을 설치한다.

 

 

1.geoip-api-c-master.zip 다운로드 & 설치 

https://github.com/maxmind/geoip-api-c

geoip-api-c-master.zip
0.18MB

1-1. 파일 다운로드

1-2. 압축풀고 들어가서 ./bootstrap

ㄴ여기서 

~/src/apache_sadong/geoip-api-c-master]# /usr/local/bin/autoreconf -fiv
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/local/bin/autoconf --force
configure.ac:14: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/local/bin/autoconf failed with exit status: 1

위와같이 libtool 관련 에러 발생하면 libtool 이거 받아서 압축풀고 ./configure make make install 해서 설치

libtool-2.4.2.tar.gz
2.51MB

 

1-3./configure --prefix=/usr/local/geoip ;make ;make install

 

2.geoip 컨츄리 파일 받고 넣기
https://dev.maxmind.com/geoip/geoip2/geolite2/

ㄴ용량이 커서 업로드가 안됨, GeoLite2-City-CSV_날짜 파일 받으면됩니다.

2-1.일전에 geoip iptalbles 에 올리는걸로 컨버팅하는 스크립트 했었는데 이번 스크립트는 또 다른거다.

이번 버전은 파이썬 2.7버전에서 실행되는 스크립트다.(2.7 미만의 버전은 해당 스크립트 에러남)

# git clone https://github.com/sherpya/geolite2legacy

# cd geolite2legacy

# curl -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip

# ./geolite2legacy.py -i GeoLite2-Country-CSV.zip -f geoname2fips.csv -o GeoIP.dat

ㄴ이거 할 때 ipaddr 모듈 없다하면 pip install ipaddr 명령어로 설치해야한다.

깔끔하게 GEOIP.dat 파일이 생겼다.
geoip.dat 파일은 여기다가 한달에 한번정도 주기적으로 업로드를 해야겠다. 

 

GeoIP.dat
1.88MB

2-2.geoip.dat 파일을 /usr/local/GeoIP/share/GeoIP 여따가 넣어준다.

 

 

3.geoip-api-mod_geoip2-1.2.10.tar.gz 다운로드

geoip-api-mod_geoip2-1.2.10.tar.gz
0.01MB

3-1. 파일 다운로드 받고 압축풀고 해당 디렉토리로 들어가면 mod_geoip.c 가 있다. 해당 경로에서

[root@localhost ~/src/apache_sadong/geoip-api-mod_geoip2-1.2.10]# /home/apache/bin/apxs  -i -a -L /usr/local/GeoIP/lib -I /usr/local/GeoIP/include -l GeoIP -c ./mod_geoip.c 

이렇게 하면 아파치에 geoip 모듈 탑재 완료.

 

3-2. 이제 다 됐으면 특정 국가만 허용예시

GeoIPDBFile 이부분은 geoip db 파일을 뭘로 할꺼냐고 그 뒤에 flag 는 Standard  만 있는게 아니다.
MemoryCache / Standard / CheckCache / IndexCache 요렇게 4개가 있다.
메뉴얼에는 전부 MemoryCache 로 돼 있으니까 나도 MemoryCache  로 

각 플래그에 대한 설명은 https://dev.maxmind.com/geoip/legacy/mod_geoip2/ 참고

 

 

특정 국가에만 접근 허용

          <Directory /home>                  
                Options FollowSymLinks MultiViews
                AllowOverride FileInfo
                Order deny,allow  
                SetEnvIf GEOIP_COUNTRY_CODE KR AllowCountry
                Deny from all
                Allow from env=AllowCountry

</Directory>

 

 

ps.

아파치 어쎄스 로그에 국가코드 남기고 싶으면 로그 포멧을 아래로 하면됨
LogFormat “%V [%h] %u %t %D \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”   GeoIP_Address=\”%{GEOIP_ADDR}e\” Country_Code=\”%{GEOIP_COUNTRY_CODE}e\” Country_Name=\”{GEOIP_COUNTRY_NAME}e\”” vcommon

+ Recent posts