随笔分类 - Ansible
摘要:# cat check_env.sh #!/bin/bash # echo " 检查CPU " ansible all -m shell -a "cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c" echo " 检查内存 " ansible
阅读全文
posted @ 2023-03-15 08:53
Varden
摘要:#示例文件 tasks: - yum: name: "{{ item }}" state: present loop: - httpd - memcached tags: - packages - template: src: templates/src.j2 dest: /etc/foo.conf
阅读全文
posted @ 2020-10-29 09:05
Varden
摘要:#在一个task中循环某个操作 - name: "Modify key file permissions" file: path: "{{ ceph_conf_dir }}/ceph.client.admin.keyring" mode: 0644 delegate_to: "{{ item }}"
阅读全文
posted @ 2020-10-29 09:00
Varden
摘要:#目录结构示例: site.yml webservers.yml fooservers.yml roles/ common/ tasks/ handlers/ files/ templates/ vars/ defaults/ meta/ webservers/ tasks/ defaults/ m
阅读全文
posted @ 2020-10-29 08:49
Varden
摘要:#包含play - hosts: localhost tasks: - debug: msg: play1 - name: Include a play after another play include: otherplays.yaml #包含task列表 - hosts: all tasks:
阅读全文
posted @ 2020-10-29 08:42
Varden
摘要:#直接在task中定义: - hosts: all remote_user: root tasks: - apt: name=cobbler state=installed environment: http_proxy: http://proxy.example.com:8080 #在task中调
阅读全文
posted @ 2020-10-28 17:44
Varden
摘要:#顶层目录结构应当包括下列文件和目录 production # inventory file for production servers 关于生产环境服务器的清单文件 stage # inventory file for stage environment 关于 stage 环境服务器的清单文件
阅读全文
posted @ 2020-10-28 17:11
Varden
摘要:#lineinfile模块重要参数说明 backrefs 布尔值 选择: no ←-默认 yes 与state = present一起使用。 如果设置为yes,则行可以包含后向引用(位置和命名),如果正则表达式匹配,则将进行填充。 该参数稍微改变了模块的操作; insertbefore和insert
阅读全文
posted @ 2020-10-28 15:25
Varden
摘要:#模块使用 通过命令行来执行三个不同的模块: ansible webservers -m service -a "name=httpd state=started" ansible webservers -m ping ansible webservers -m command -a "/sbin/
阅读全文
posted @ 2020-10-28 15:23
Varden
摘要:#获取执行命令的输出:register - name: echo date command: date register: date_output - name: echo date_output command: echo "30" when: date_output.stdout.split('
阅读全文
posted @ 2020-10-28 14:59
Varden
摘要:#优化前的准备:收集数据 cd /etc/ansible mkdir callback_plugins cd callback_plugins wget https://raw.githubusercontent.com/jlafon/ansible-profile/master/callback_
阅读全文
posted @ 2020-10-28 14:17
Varden
摘要:需要长时间运行的命令可以放到后台去,在命令开始运行后我们也可以检查运行的状态.如果运行命令后,不想获取返回的信息, 可执行如下命令: ansible all -B 3600 -P 0 -a "/usr/bin/long_running_operation --do-stuff" 如果你确定要在命令运
阅读全文
posted @ 2020-10-28 11:52
Varden
摘要:确认某个服务在所有的webservers上都已经启动: ansible webservers -m service -a "name=httpd state=started" 或是在所有的webservers上重启某个服务(译者注:可能是确认已重启的状态?): ansible webservers
阅读全文
posted @ 2020-10-28 11:50
Varden
摘要:直接使用 git 部署 webapp: ansible webservers -m git -a "repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD"
阅读全文
posted @ 2020-10-28 11:48
Varden
摘要:使用 ‘user’ 模块可以方便的创建账户,删除账户,或是管理现有的账户: ansible all -m user -a "name=foo password=<crypted password here>" ansible all -m user -a "name=foo state=absent
阅读全文
posted @ 2020-10-28 11:46
Varden
摘要:确认一个软件包已经安装,但不去升级它: ansible webservers -m yum -a "name=acme state=present" 确认一个软件包的安装版本: ansible webservers -m yum -a "name=acme-1.5 state=present" 确认
阅读全文
posted @ 2020-10-28 11:45
Varden
摘要:以并行的方式同时 SCP 大量的文件到多台机器. 命令如下: ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts" 使用 file 模块可以做到修改文件的属主和权限: ansible webservers -m file -a "de
阅读全文
posted @ 2020-10-28 11:41
Varden
摘要:#Ansible提供两种方式去完成任务 一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂的任务. /usr/bin/ansible /usr/bin/ansible-playbook 例子:使用 Ansible 的命令行工具来重启 At
阅读全文
posted @ 2020-10-28 11:35
Varden
摘要:#Patterns ansible <pattern_goes_here> -m <module_name> -a <arguments> 示例如下: ansible webservers -m service -a "name=httpd state=restarted" 如下的patterns等
阅读全文
posted @ 2020-10-28 11:33
Varden
摘要:#Inventory参数说明 ansible_ssh_host 将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置. ansible_ssh_port ssh端口号.如果不是默认的端口号,通过此变量设置. ansible_ssh_user 默认的 ssh 用户名 ansible
阅读全文
posted @ 2020-10-28 11:31
Varden

浙公网安备 33010602011771号