城市焦点商城网站建设案例杭州商城型网站建设
- 作者: 五速梦信息网
- 时间: 2026年03月21日 11:31
当前位置: 首页 > news >正文
城市焦点商城网站建设案例,杭州商城型网站建设,网店推广策划方案,网站域名注册备案教程文章目录 ansible配置文件的优先级尝试开始进行操作ansible常用模块ansible 的playbook示例安装phpplaybook中变量的引用 ansible yum install -y ansible 测试是否可用 ansible localhost -m ping /etc/ansible/ansible.cfg #xff1a;主配置文件#xff0c;配置 ansible… 文章目录 ansible配置文件的优先级尝试开始进行操作ansible常用模块ansible 的playbook示例安装phpplaybook中变量的引用 ansible yum install -y ansible 测试是否可用 ansible localhost -m ping /etc/ansible/ansible.cfg 主配置文件配置 ansible 工作特性 /etc/ansible/hosts 配置主机清单文件 /etc/ansible/roles/ 存放 ansible 角色的目录主配置文件存在 /etc/anible/ansible.cfg 指定特权用户 [privilege_escalation] becomeTrue become_methodsudo become_useruser become_ask_passFalseansibleadhocplaybooktasksRolesRoles方式编排web集群架构 配置文件的优先级
- 最先查找 $ANSIBLE_CONFIG 变量
- 其次查找当前项目目录下 ansible.cfg
- 然后查找用户家目录下的 .ansible.cfg
- 最后查找 /etc/ansible/ansible.cfgInventory 文件主要用来填写被管理主机以及主机组信息(逻辑上定义) 默认 Inventory 文件为 /etc/ansible/hosts 当然也可以自定义一个文件当执行 ansible 命令时使用 -i 选项指定 Inventory 文件位置 配置主机清单 [webservers] 172.16.1.7 172.16.1.8 ansible_becomeyesansible_becomeyes 这个的意思是加上sudo尝试开始进行操作 ad-hoc执行步骤 1.加载自己的配置文件默认 /etc/ansible/ansible.cfg 2.查找对应的主机配置文件找到要执行的主机或者组 3.加载自己对应的模块文件如 command 4.通过 ansible 将模块或命令生成对应的临时 py 文件并将该文件传输至远 程服务器对应执行用户 \(HOME/.ansible/tmp/ansible-tmp-number/XXX.PY 5.执行用户家目录的 文件 6.给文件 x 执行 7.执行并返回结果 8.删除临时 py 文件 sleep 0 退出使用 ad-hoc 执行一次远程命令注意观察返回结果的颜色 绿色: 代表被管理端主机没有被修改 黄色: 代表被管理端主机发现变更 红色: 代表出现了故障注意查看提示ansible常用模块 command模块 [rootmanger ~]# ansible localhost -m command -a chdir/root echo \)PWDansible localhost -m command -a creates/data/file ifconfig eth0shell 模块 参数 选项 含义 chdir chdir /opt 执行ansible时切换到指定的目录 creates creates /data/file 如果文件存在则跳过执行 removes removes /data/file 如果文件存在则执行 ansible localhost -m shell -a ifconfig eth0|awk NR2 scripts 模块ansible webservers -m script -a /data/yum.shcopy模块 ansible webservers -m copy -a src./httpd.conf dest/etc/httpd/conf/httpd.conf ownerroot grouproot mode644file模块ansible webservers -m file -a path/tmp/foo.conf statetouch mode666ansible webservers -m file -a path/tmp/foo statedirectory mode777 ansible webservers -m file -a path/tmp/foo statedirectory ownerroot grouproot mode777 recurseyes等模块有很多平时用不到这里做一个大概记录ansible 的playbook playbook 是一个 由 yaml 语法编写的文本文件它由 play 和 task 两部分组 成。 play 主要定义要操作主机或者主机组 task 主要定义对主机或主机组具体执行的任务可以是一个任务也可以是多个 任务模块 总结: playbook 是由一个或多个 play 组成一个 play 可以包含多个 task 任 务。 可以理解为: 使用多个不同的模块来共同完成一件事情。1) playbook 是对 AD-Hoc 的一种编排方式。
- playbook 可以持久运行而 Ad-Hoc 只能临时运行。
- playbook 适合复杂的任务而 Ad-Hoc 适合做快速简单的任务。
- playbook 能控制任务执行的先后顺序。语法 描述 缩进 YAML使用固定的缩进风格表示层级结构,每个缩进由两个空格组成, 不能 使用tabs 冒号 以冒号结尾的除外其他所有冒号后面所有必须有空格。 短横线 表示列表项使用一个短横杠加一个空格。多个项使用同样的缩进级别 作为同一列表。示例 $cat installed_httpd.yml #1.定义play #2.定义task、Installed、Configure、Init、Systemd- hosts: webserverstasks:- name: Installed Httpd Serveryum:name: httpdstate: present- name: Configure Httpd Servercopy:src: ./httpd.conf.j2dest: /etc/httpd/conf/httpd.confowner: rootgroup: rootmode: 0644backup: yesnotify: Restart Httpd Server- name: Init Httpd Servercopy:src: ./index.html.j2dest: /var/www/html/test.html- name: Systemd Httpd Serversystemd:name: httpdstate: startedenabled: yeshandlers:- name: Restart Httpd Serversystemd:name: httpdstate: restarted上面是用root 用户执行的 下面是用普通用户执行
- hosts: webserversbecome: truebecome_user: roottasks:- name: Installed Httpd Serveryum:name: httpdstate: present- name: Configure Httpd Servercopy:src: ./httpd.conf.j2dest: /etc/httpd/conf/httpd.confowner: nousergroup: nousermode: 0644backup: yesnotify: Restart Httpd Server- name: Init Httpd Servercopy:src: ./index.html.j2dest: /var/www/html/test.htmlowner: nousergroup: nousermode: 0644- name: Systemd Httpd Serversystemd:name: httpdstate: startedenabled: yeshandlers:- name: Restart Httpd Serversystemd:name: httpdstate: restarted检查语法 ansible-playbook installed_httpd.yml – syntax-check执行命令 ansible-playbook installed_httpd.yml 安装php cat install_nginx_php.yml #1.安装nginx #2.安装php #3.添加nginx虚拟主机触发重启 #4.配置php连接redis触发重启 #5.部署phpadmin、- hosts: webserversvars:web_site_directory: /ansible/admin2tasks:- name: Installed Nginx PHP Serveryum:name: {{ item }}state: presentloop:- nginx- php71w- php71w-cli- php71w-common- php71w-devel- php71w-embedded- php71w-gd- php71w-mcrypt- php71w-mbstring- php71w-pdo- php71w-xml- php71w-fpm- php71w-mysqlnd- php71w-opcache- php71w-pecl-memcached- php71w-pecl-redis- php71w-pecl-mongodbtags: Install- name: Create Nginx Process Runtime Groupgroup:name: wwwgid: 666tags: Install- name: Create Nginx Process Runtime Useruser:name: wwwuid: 666create_home: notags:- Install- Configure- name: Configure Nginx Nginx.confcopy:src: ./conf/nginx.conf.j2dest: /etc/nginx/nginx.confowner: rootgroup: rootmode: 0644notify: Restart Nginx Servertags: Configure- name: Configure Nginx VHosts ansible.oldxu.com;template:src: ./conf/ansible.oldxu.com.conf.j2dest: /etc/nginx/conf.d/ansible.oldxu.com.confnotify: Restart Nginx Server- name: Check Web Configureshell:cmd: /usr/sbin/nginx -tregister: Check_Nginxchanged_when:- Check_Nginx.stdout.find(successful)- false- name: Configure php php.inicopy:src: {{ item.src }}dest: {{ item.dest }}mode: {{ item.mode }}loop:- { src: ./conf/php.ini.j2, dest: /etc/php.ini , mode: 0644 }- { src: ./conf/php-fpm.d.www.conf.j2, dest: /etc/php-fpm.d/www.conf , mode: 0644 }notify: Restart PHP Server- name: Systemd Nginx And PHP Serversystemd:name: {{ item }}state: startedenabled: yesloop:- nginx- php-fpm# download code- name: Create Web Site Directoryfile:path: {{ web_site_directory }}state: directoryowner: wwwgroup: wwwmode: 0755- name: Unarchive Myadmin Codeunarchive:src: file/phpmyadmin.zipdest: {{ web_site_directory }}owner: wwwgroup: wwwhandlers:- name: Restart Nginx Serversystemd:name: nginxstate: restarted- name: Restart PHP Serversystemd:name: php-fpmstate: restartedplaybook中变量的引用 变量提供了便捷的方式来管理 ansible 项目中的动态值。 比如 nginx-1.12 可能 后期会反复的使用到这个版本的值那么如果将此值设置为变量后续使用和修改都 将变得非常方便。这样可以简化项目的创建和维护;在 Ansible 中定义变量分为如下三种方式
- 通过命令行传递变量参数定义
- 在play文件中进行定义变量 2.1) 通过vars定义变量 2.2) 通过vars_files定义变量
- 通过inventory在主机组或单个主机中设置变量 3.1) 通过host_vars对主机进行定义 3.2) 通过group_vars对主机组进行定义vars 形式的变量
- hosts: webserversvars:web_packages: httpdftp_packages: vsftpdtasks:- name: Output Variablesdebug:msg:- {{ web_packages }}- {{ ftp_packages }}输出结果为msg: [httpd,vsftpd]在 playbook 中使用 vars_files 指定文件作为变量文件好处就是其他的 playbook 也可以调用 [rootansible project1]# cat vars.yml web_packages: httpd ftp_packages: vsftpd- hosts: webserversvars_files:- ./vars.ymltasks:- name: Output Variablesdebug:msg:- {{ web_packages }}- {{ ftp_packages }}playbook 传送多个变量 ansible-playbook f5.yml -i hosts -e web_packagesGeoIP -e ftp_packagestelnet
- 上一篇: 城市建设与管理局网站360网站建设公司哪家好
- 下一篇: 城市门户网站模板郑州锐旗网站公司
相关文章
-
城市建设与管理局网站360网站建设公司哪家好
城市建设与管理局网站360网站建设公司哪家好
- 技术栈
- 2026年03月21日
-
城市建设学校网站管理规章制度网站建设客户去哪里找
城市建设学校网站管理规章制度网站建设客户去哪里找
- 技术栈
- 2026年03月21日
-
城市建设网站在哪人网站要以接it项目做
城市建设网站在哪人网站要以接it项目做
- 技术栈
- 2026年03月21日
-
城市门户网站模板郑州锐旗网站公司
城市门户网站模板郑州锐旗网站公司
- 技术栈
- 2026年03月21日
-
城乡建设部网站安全员证书查询百度指数排名
城乡建设部网站安全员证书查询百度指数排名
- 技术栈
- 2026年03月21日
-
城乡建设环保部网站网站内页301重定向
城乡建设环保部网站网站内页301重定向
- 技术栈
- 2026年03月21日






