随笔分类 - Ansible
摘要:故障问题:ansible远程调用startup.sh启动tomcat,启动失败。解决方法:ansible调用shell脚本启动tomcat得加上nohup 后面还不能跟 “&” ansible peixun-145 -m shell -a "nohup /script/fc_tomcat.sh co
阅读全文
摘要:1.Jinja2模板逻辑判断 1)循环 #shell脚本的循环 [root@m01 ~]# vim xh.sh #!/bin/bash for i in `seq 10` do echo $i done #Jinja2的循环表达式 {% for i in range(10) %} echo $i {
阅读全文
摘要:默认playbook会检测task执行的返回状态,如果遇到错误则会立即终止playbook的后续task执行,然而有些时候playbook即使执行错误了也要让其继续执行。 加入参数:ignore_errors:yes 忽略错误 - name: Get PHP Install status shell
阅读全文
摘要:1)编写安装nginx [root@m01 ~]# cat nginx.yml - name: Install Nginx Server yum: name: nginx state: present 2)编写启动nginx [root@m01 ~]# cat start.yml - name: S
阅读全文
摘要:1.标签的作用 默认情况下,Ansible在执行一个playbook时,会执行playbook中定义的所有任务,Ansible的标签(tag)功能可以给单独任务甚至整个playbook打上标签,然后利用这些标签来指定要运行playbook中的个别任务,或不执行指定的任务。 2.打标签的方式 1.对一
阅读全文
摘要:1.什么是触发器 handler用来执行某些条件下的任务,比如当配置文件发生变化的时候,通过notify触发handler去重启服务。 在saltstack中也有类似的触发器,写法相对Ansible简单,只需要watch,配置文件即可 2.配置触发器 [root@m01 ~]# cat handle
阅读全文
摘要:1.定义变量安装多服务 [root@m01 ~]# vim install.yml - hosts: nfs tasks: - name: Install Server yum: name: "{{ package }}" state: present vars: package: - httpd
阅读全文
摘要:一、playbook条件语句 1.判断主机 [root@m01 ~]# cat lnmp5.yml - hosts: nfs_group tasks: - name: Install nfs Server yum: name: nfs-utils state: present - name: Ins
阅读全文
摘要:一、变量介绍 1.概念 变量提供了便捷的方式来管理Ansible playbook的每一个项目中的动态值,比如nginx-1.6.3这个软件包的版本,在其它地方或许会反复使用,那么如果讲此值设置为变量,然后再在其他的playbook中调用,会方便许多。如此一来还方便维护,减少维护的成本。 2.定义变
阅读全文
摘要:1.什么是playbook PlayBook即"剧本","兵书"之意,PlayBook是由以下部分组成的 play(host): 定义的是主机的角色。(主角还是配角) Book(task): 定义的是具体执行的任务。(角色的台词和动作) playbook: 由一个或多个play(角色)组成,一个pl
阅读全文
摘要:1)使用 1.获取所有主机信息 [root@m01 ~]# ansible web01 -m setup 2.获取主机名(使用setup获取的信息,指定对应的小标题获取指定的信息) [root@m01 ~]# ansible web01 -m setup -a 'filter=ansible_fqd
阅读全文
摘要:1.unarchive 解压模块 1)帮助语法 - name: Unarchive a file that is already on the remote machine unarchive: src: /tmp/foo.zip #要解压的包 dest: /usr/local/bin #解压到目标
阅读全文
摘要:1.磁盘挂载mount模块 1)帮助语法 EXAMPLES: # Before 2.3, option 'name' was used instead of 'path' - name: Mount DVD read-only mount: path: /mnt/dvd #挂载的目录(nfs客户端)
阅读全文
摘要:1.group模块 1)帮助语法 EXAMPLES: - name: Ensure group "somegroup" exists group: name: somegroup #组名字 state: present #创建用户组 absent #删除用户组 gid: 666 #用户组ID 2)实
阅读全文
摘要:1. get_url 模块 1)帮助语法 [root@m01 ~]# ansible-doc get_url EXAMPLES: - name: Download foo.conf get_url: url: http://example.com/path/file.conf dest: /etc/
阅读全文
摘要:1.yum模块 1)语法帮助 [root@m01 ~]# ansible-doc yum EXAMPLES: - name: install the latest version of Apache yum: name: httpd state: latest name: httpd #服务的名字
阅读全文
摘要:1.command模块 [root@m01 ~]# ansible 'web01' -m command -a 'free -m' web01 | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 972 110 4
阅读全文
摘要:1.什么是ad-hoc ad-hoc简而言之就是远程执行“临时命令”,执行完即结束,并不会保存 2.ad-hoc使用场景 比如在多台机器上查看某个进程是否启动,或拷贝指定文件到本地,等等 3.ad-hoc使用 [root@m01 ~]# ansible 'web01' -m shell -a 'fr
阅读全文
摘要:1)方式一: #ip+端口+用户+密码 [root@m01 ~]# vim /etc/ansible/hosts [web01] 172.16.1.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1' [web03] 172
阅读全文
摘要:[root@m01 ~]# cat /etc/ansible/ansible.cfg #inventory = /etc/ansible/hosts #主机列表配置文件 #library = /usr/share/my_modules/ #库文件存放目录 #remote_tmp = ~/.ansib
阅读全文