摘要: #直接在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 阅读(1453) 评论(0) 推荐(0) 编辑
摘要: #使用htpasswd生成加密的密码文件方法 apt-get install apache2-utils htpasswd -bc /etc/squid/passwdfile test test 阅读全文
posted @ 2020-10-28 17:40 Varden 阅读(412) 评论(0) 推荐(0) 编辑
摘要: #生成加密的Linux用户密码方法 apt install whois mkpasswd --method=sha-512 阅读全文
posted @ 2020-10-28 17:37 Varden 阅读(462) 评论(0) 推荐(0) 编辑
摘要: #针对大量节点的配置方法 在其中一个节点通过 ssh-keygen 生成公私钥 $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa 把公钥 id_rsa.pub 内容贴到 authorized_keys 文件并修改文件权限 $ cat ~/.ssh/id_rsa.p 阅读全文
posted @ 2020-10-28 17:35 Varden 阅读(214) 评论(0) 推荐(0) 编辑
摘要: #顶层目录结构应当包括下列文件和目录 production # inventory file for production servers 关于生产环境服务器的清单文件 stage # inventory file for stage environment 关于 stage 环境服务器的清单文件 阅读全文
posted @ 2020-10-28 17:11 Varden 阅读(1093) 评论(0) 推荐(0) 编辑
摘要: #lineinfile模块重要参数说明 backrefs 布尔值 选择: no ←-默认 yes 与state = present一起使用。 如果设置为yes,则行可以包含后向引用(位置和命名),如果正则表达式匹配,则将进行填充。 该参数稍微改变了模块的操作; insertbefore和insert 阅读全文
posted @ 2020-10-28 15:25 Varden 阅读(258) 评论(0) 推荐(0) 编辑
摘要: #模块使用 通过命令行来执行三个不同的模块: 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 阅读(335) 评论(0) 推荐(0) 编辑
摘要: #获取执行命令的输出: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 阅读(177) 评论(0) 推荐(0) 编辑
摘要: #优化前的准备:收集数据 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 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 需要长时间运行的命令可以放到后台去,在命令开始运行后我们也可以检查运行的状态.如果运行命令后,不想获取返回的信息, 可执行如下命令: ansible all -B 3600 -P 0 -a "/usr/bin/long_running_operation --do-stuff" 如果你确定要在命令运 阅读全文
posted @ 2020-10-28 11:52 Varden 阅读(2110) 评论(0) 推荐(0) 编辑
摘要: 确认某个服务在所有的webservers上都已经启动: ansible webservers -m service -a "name=httpd state=started" 或是在所有的webservers上重启某个服务(译者注:可能是确认已重启的状态?): ansible webservers 阅读全文
posted @ 2020-10-28 11:50 Varden 阅读(588) 评论(0) 推荐(0) 编辑
摘要: 直接使用 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 阅读(1576) 评论(0) 推荐(0) 编辑
摘要: 使用 ‘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 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 确认一个软件包已经安装,但不去升级它: 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 阅读(438) 评论(0) 推荐(0) 编辑
摘要: 以并行的方式同时 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 阅读(1338) 评论(0) 推荐(0) 编辑
摘要: #Ansible提供两种方式去完成任务 一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂的任务. /usr/bin/ansible /usr/bin/ansible-playbook 例子:使用 Ansible 的命令行工具来重启 At 阅读全文
posted @ 2020-10-28 11:35 Varden 阅读(483) 评论(0) 推荐(0) 编辑
摘要: #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 阅读(148) 评论(0) 推荐(0) 编辑
摘要: #Inventory参数说明 ansible_ssh_host 将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置. ansible_ssh_port ssh端口号.如果不是默认的端口号,通过此变量设置. ansible_ssh_user 默认的 ssh 用户名 ansible 阅读全文
posted @ 2020-10-28 11:31 Varden 阅读(447) 评论(0) 推荐(0) 编辑
摘要: #主机变量 [atlanta] host1 http_port=80 maxRequestsPerChild=808 host2 http_port=303 maxRequestsPerChild=909 #组变量 [atlanta] host1 host2 [atlanta:vars] ntp_s 阅读全文
posted @ 2020-10-28 11:29 Varden 阅读(3024) 评论(0) 推荐(0) 编辑
摘要: #主机与组 /etc/ansible/hosts 文件的格式: mail.example.com [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.exampl 阅读全文
posted @ 2020-10-28 11:26 Varden 阅读(191) 评论(0) 推荐(0) 编辑