标签:device www files echo 配置 roo 没有 yaml tmp
yum -y install ansible
需要在被分发的服务器上安装支持包 [root@www ~]# mount /dev/sr0 /media/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@www ~]# yum -y install libselinux-python
[root@ansible myroles]# tree /myroles/ /myroles/ ├── nginx.yaml #nginx模组入口配置文件 └── roles └── nginx #nginx原型模组目录 ├── files ├── handlers ├── tasks │ └── main.yaml #nginx模组的tasks任务配置文件 ├── templates └── vars 7 directories, 2 files
---
- hosts: all
gather_facts: True
roles:
- nginx
#!/bin/bash mkdir -p /media/cdrom umount /dev/sr0 &>/dev/null mount /dev/sr0 /media/cdrom &>/dev/null dir=/etc/yum.repos.d [ -d $dir ] || mkdir -p $dir cd $dir mv * /tmp/ cat >/etc/yum.repos.d/local.repo << KOF [local] name=localrepo baseurl=file:///media/cdrom/ KOF yum -y clean all &>/dev/null [ $? -eq 0 ] || echo "clean erro" yum makecache &>/dev/null || echo "erro cache" which "wget" [ $? -eq 0 ] || /usr/bin/yum -y install wget &>/dev/null /usr/bin/wget http://mirrors.aliyun.com/repo/epel-6.repo [ $? -eq 0 ] || (/bin/echo "yun源出错" && exit) /usr/bin/yum -y clean all &>/dev/null /usr/bin/yum makecache &>/dev/null [ $? -eq 0 ] || (/bin/echo "yun缓存错误" && exit) /usr/bin/yum -y install pcre-deved openssl-devel &>/dev/null [ $? -eq 0 ] || /bin/echo "pcre error" useradd -M -s /sbin/nologin nginx &>dev/null cd ~ tar xf nginx-1.10.2.tar.gz -C /usr/src/ cd /usr/src/nginx-1.10.2/ ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.2/ --with-http_stub_status_module --with-http_ssl_module && make && make install &>/dev/null
- name: t1 copy: src=nginx-1.10.2.tar.gz dest=/root/ register: ttt - debug: var=ttt - name: t2 script: nginx.sh register: rrr - debug: var=rrr
[root@bogon myroles]# ansible-playbook nginx.yaml PLAY [all] ************************************************************************************************* TASK [Gathering Facts] ************************************************************************************* ok: [web1] ok: [web2] TASK [nginx : t1] ****************************************************************************************** ok: [web2] ok: [web1] TASK [nginx : debug] *************************************************************************************** ok: [web1] => { "ttt": { "changed": false, "checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547", "dest": "/root/nginx-1.10.2.tar.gz", "diff": { "after": { "path": "/root/nginx-1.10.2.tar.gz" }, "before": { "path": "/root/nginx-1.10.2.tar.gz" } }, "failed": false, "gid": 0, "group": "root", "mode": "0644", "owner": "root", "path": "/root/nginx-1.10.2.tar.gz", "secontext": "unconfined_u:object_r:admin_home_t:s0", "size": 910812, "state": "file", "uid": 0 } } ok: [web2] => { "ttt": { "changed": false, "checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547", "dest": "/root/nginx-1.10.2.tar.gz", "diff": { "after": { "path": "/root/nginx-1.10.2.tar.gz" }, "before": { "path": "/root/nginx-1.10.2.tar.gz" } }, "failed": false, "gid": 0, "group": "root", "mode": "0644", "owner": "root", "path": "/root/nginx-1.10.2.tar.gz", "secontext": "unconfined_u:object_r:admin_home_t:s0", "size": 910812, "state": "file", "uid": 0 } } TASK [nginx : t2] ****************************************************************************************** changed: [web2] changed: [web1] TASK [nginx : debug] *************************************************************************************** ok: [web1] => { "rrr": { "changed": true, "failed": false, "rc": 0, "stderr": "Shared connection to 192.168.200.131 closed.\r\n", "stderr_lines": [ "Shared connection to 192.168.200.131 closed." ], "stdout": "/usr/bin/wget\r\n--2018-11-12 19:02:03-- http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... failed: Name or service not known.\r\nwget: unable to resolve host address “mirrors.aliyun.com”\r\nyun源出错\r\n", "stdout_lines": [ "/usr/bin/wget", "--2018-11-12 19:02:03-- http://mirrors.aliyun.com/repo/epel-6.repo", "Resolving mirrors.aliyun.com... failed: Name or service not known.", "wget: unable to resolve host address “mirrors.aliyun.com”", "yun源出错" ] } } ok: [web2] => { "rrr": { "changed": true, "failed": false, "rc": 0, "stderr": "Shared connection to 192.168.200.133 closed.\r\n", "stderr_lines": [ "Shared connection to 192.168.200.133 closed." ], "stdout": "/usr/bin/wget\r\n--2018-11-12 16:03:20-- http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...\r\nConnecting to mirrors.aliyun.com|122.72.3.220|:80... connected.\r\nHTTP request sent, awaiting response... 200 OK\r\nLength: 664 [application/octet-stream]\r\nSaving to: “epel-6.repo”\r\n\r\n\r 0% [ ] 0 --.-K/s \r100%[======================================>] 664 --.-K/s in 0s \r\n\r\n2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]\r\n\r\n", "stdout_lines": [ "/usr/bin/wget", "--2018-11-12 16:03:20-- http://mirrors.aliyun.com/repo/epel-6.repo", "Resolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...", "Connecting to mirrors.aliyun.com|122.72.3.220|:80... connected.", "HTTP request sent, awaiting response... 200 OK", "Length: 664 [application/octet-stream]", "Saving to: “epel-6.repo”", "", "", " 0% [ ] 0 --.-K/s ", "100%[======================================>] 664 --.-K/s in 0s ", "", "2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]", "" ] } } PLAY RECAP ************************************************************************************************* web1 : ok=5 changed=1 unreachable=0 failed=0 web2 : ok=5 changed=1 unreachable=0 failed=0
标签:device www files echo 配置 roo 没有 yaml tmp
原文地址:https://www.cnblogs.com/cash-su/p/9988129.html