ansible之playbook自动化安装nginx
---- hosts: 192.168.1.194 192.168.1.195
gather_facts: no
remote_user: root
#become_method: sudo
#become_user: root
vars:
- base_dir: "/home/workspace"
- install_dir: "/usr/local/rktsapps"
tasks:
- include: base-install.yml
- name: copy nginx dir to remote servers.
copy:
src: "{{ base_dir }}/ansible_home/auto_deploy/software/nginx"
dest: "{{ base_dir }}/auto_deploy/software/"
- name: copy nginx conf to remote servers.
copy:
src: "{{ base_dir }}/ansible_home/auto_deploy/config_file/nginx"
dest: "{{ base_dir }}/auto_deploy/config_file/"
- name: copy install script to remote servers.
copy:
src: "{{ base_dir }}/ansible_home/auto_deploy/auto_install.sh"
dest: "{{ base_dir }}/auto_deploy/"
- name: test if nginx has been installed in remote server.
shell: ls "{{ install_dir }}/nginx/sbin/nginx"
ignore_errors: True
register: result
- name: execute shell script to install nginx in remote servers.
shell: sh auto_install.sh nginx
ignore_errors: True
args:
chdir: "{{ base_dir }}/auto_deploy/"
when: result|failed
- name: delete auto_install.sh .
file:
path: "{{ base_dir }}/auto_deploy/auto_install.sh"
state: absent
页:
[1]