Ansible Ad-hoc

강재민·2022년 6월 21일
0

모든 모듈이 정리된 링크..
https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html


Ad-hoc 명령어 기본

ansible <HOST_PATTERN> -m <MODULE> -a <PARAMETER>

Ad-hoc 명령으로 Wordpress 구성

yum 모듈에 대한 링크..
https://docs.ansible.com/ansible/2.9/modules/yum_module.html#yum-module

ansible wp -m yum -a "name=https://rpms.remirepo.net/enterprise/remi-release-7.rpm state=present validate_certs=no" -b

### wp host에 실행
### yum 모듈을 사용
### 파라미터들을 "name= state= validate_certs= "형식으로 추가
### -b 옵션 root권한으로 실행

위 ad-hoc명령어와 아래 플레이북은 같은 의미이다.

- hosts: wp
  tasks:
    - yum:
        name: https://rpms.remirepo.net/enterprise/remi-release-7.rpm
        state: present
        validate_certs: no

아래 표에 있는 각 내용들로 구성된 것이다.


yum_repository 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/yum_repository_module.html#yum-repository-module

ansible wp -m yum_repository -a 'name=remi-safe file=remi-safe mirrorlist=http://cdn.remirepo.net/enterprise/7/safe/mirror description=remi-safe enabled=no' -b
ansible wp -m yum_repository -a 'name=remi-php74 file=remi-php74 mirrorlist=http://cdn.remirepo.net/enterprise/7/php74/mirror description=remi-php74 enabled=yes gpgcheck=yes gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi' -b
ansible wp -m yum -a 'name=httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL state=installed' -b

service 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/service_module.html#service-module

ansible wp -m service -a 'name=httpd state=started enabled=yes' -b
ansible wp -m service -a 'name=mariadb state=started enabled=yes' -b

get_url 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/get_url_module.html#get-url-module

ansible wp -m get_url -a 'url=https://wordpress.org/wordpress-5.9.3.tar.gz dest=/home/vagrant'

unarchive 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/unarchive_module.html#unarchive-module

ansible wp -m unarchive -a 'src=/home/vagrant/wordpress-5.9.3.tar.gz remote_src=yes dest=/var/www/html owner=apache group=apache' -b

mysql_db 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/mysql_db_module.html#mysql-db-module

ansible wp -m mysql_db -a 'name=wordpress state=present login_user=root'

mysql_user 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/mysql_user_module.html#mysql-user-module

ansible wp -m mysql_user -a 'name=wpadm password=P@ssw0rd state=present login_user=root priv="wordpress.*:ALL"'

copy 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/copy_module.html#copy-module

ansible wp -m copy -a 'src=/var/www/html/wordpress/wp-config-sample.php remote_src=yes dest=/var/www/html/wordpress/wp-config.php owner=apache group=apache' -b

replace 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/replace_module.html#replace-module

ansible wp -m replace -a 'path=/var/www/html/wordpress/wp-config.php regexp=database_name_here replace=wordpress' -b
ansible wp -m replace -a 'path=/var/www/html/wordpress/wp-config.php regexp=username_here replace=wpadm' -b
ansible wp -m replace -a 'path=/var/www/html/wordpress/wp-config.php regexp=password_here replace=P@ssw0rd' -b

file 모듈에 대한 내용..
https://docs.ansible.com/ansible/2.9/modules/file_module.html#file-module

ansible wp -m service -a 'name=httpd state=stopped' -b
ansible wp -m service -a 'name=mariadb state=stopped' -b
ansible wp -m file -a 'path=/var/www/html/wordpress state=absent' -b
ansible wp -m file -a 'path=/home/vagrant/wordpress-5.9.3.tar.gz state=absent' -b
ansible wp -m yum -a 'name=httpd,php,php-mysqlnd,mariadb,mariadb-server,python2-PyMySQL autoremove=yes state=absent' -b
ansible wp -m file -a 'name=/var/lib/mysql state=absent' -b
ansible wp -m yum -a 'name=remi-release autoremove=yes state=absent' -b

return value

https://docs.ansible.com/ansible/2.9/reference_appendices/common_return_values.html


실행할 시스템 제한

ansible-playbook wordpress.yaml --limit 192.168.100.12

0개의 댓글