系统初始化
ansible-playbook /root/ansible/yaml/initos-playbook.yaml --tags="initos" --list-hosts
[root@prome-01 file]# cat /root/ansible/yaml/initos-playbook.yaml
- hosts: initos #定义需要执行主机
remote_user: root #远程用户
vars:
file: /opt/initos/
tags: initos
tasks: #定义一个任务的开始
- name: create new dir #定义任务的名称
file: name=/opt/initos state=directory #调用模块,具体要做的事情
- name: "copy files"
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: 755
with_items:
- {src: "/etc/ansible/file/360-wins(192.66.255.174_8080_8090).exe", dest: "/opt/initos/" }
- {src: "/etc/ansible/file/360linuxc(192.66.255.174_8080_8090).sh", dest: "/opt/initos/" }
- {src: "/etc/ansible/file/jgjclvcentos7.sh", dest: "/opt/initos/" }
- {src: "/etc/ansible/file/clv1.sh", dest: "/opt/initos/" }
- {src: "/etc/ansible/file/yum.sh", dest: "/opt/initos/" }
- name: yuminstall
tags: yum
shell: cd /opt/initos/;/bin/sh yum.sh
- name: exroot
tags: exroot
shell: cd /opt/initos/;/bin/sh clv1.sh
- name: datemount
tags: datemount
shell: cd /opt/initos/;/bin/sh jgjclvcentos7.sh
- hosts: openssh #定义需要执行主机
tags: openssh
remote_user: root #远程用户
tasks: #定义一个任务的开始
- name: create new dir #定义任务的名称
file: name=/opt/openssh state=directory #调用模块,具体要做的事情
- name: "copy files"
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: 755
with_items:
- {src: "/etc/ansible/file/openssh-9.6p1.tar.gz", dest: "/opt/openssh/" }
- {src: "/etc/ansible/file/openssl-1.1.1q.tar.gz", dest: "/opt/openssh/" }
- {src: "/etc/ansible/file/zlib-1.3.tar.gz", dest: "/opt/openssh/" }
- {src: "/etc/ansible/file/openssh.sh", dest: "/opt/openssh/" }
- name: Execute the script
shell: cd /opt/openssh/;sh openssh.sh
标签:opt,src,dest,案例,initos,ansible,file
From: https://www.cnblogs.com/OpenSourceSite/p/18327479