360建筑网是什么网站,alexa排名搜索,怎么申请自己的域名,浙江省住房和城乡建设厅网站打不开模块
7、hostname模块#xff1a;
远程主机名管理模块
ansible 192.168.10.202 -m hostname -a nameliu 8、copy模块#xff1a;
用于复制指定的主机文件到远程主机的模块
常用参数#xff1a;
dest: 指出要复制的文件在哪#xff0c;必须使用绝对路径。如果源目标是…模块
7、hostname模块
远程主机名管理模块
ansible 192.168.10.202 -m hostname -a nameliu 8、copy模块
用于复制指定的主机文件到远程主机的模块
常用参数
dest: 指出要复制的文件在哪必须使用绝对路径。如果源目标是目录指目标也得是目录。如果目标的文件存在会覆盖原有内容src 复制文件的源最好使用绝对路径原目标是目录指目标也是目录owner指出文件的所有者group指定文件的所在组content从主机复制指定内容到目标主机使用content就不能使用srcmode可以给予复制之后的文件的权限
复制文件夹不能为空
ansible 192.168.10.202 -m copy -a src/opt/guoqi dest/opt/guoqi1 mode700 复制文件
ansible 192.168.10.202 -m copy -a src/opt/ky32.txt dest/opt/ky32.txt ownerguoqi groupguoqi mode600 content
ansible 192.168.10.202 -m copy -a contenthello lyw dest/opt/hello.txt 9、file模块
文件模块跟目录没有关系 管理文件属性 owner、group0、mode等 statelink创建链接文件 statetouch创建文件 stateabsent删除文件
file模块创建一个文件ky32.txt 所有者和所在组guoqi 权限700
ansible 192.168.10.202 -m file -a ownerguoqi groupguoqi mode700 path/opt/ky32.txt 创建软连接
ansible 192.168.10.202 -m file -a path/opt/fatab.link src/opt/fstab.bak statelink 删除软连接
ansible 192.168.10.202 -m file -a path/opt/fatab.link stateabsent 10、yum模块
远程主机上安装与卸载软件包在目标主机上的操作都是后台运行不影响其他用户的使用。
安装
ansible 192.168.10.202 -m yum -a nametree 卸载
ansible 192.168.10.202 -m yum -a nametree stateabsent 查询远程主机httpd的状态 2、开启 3、访问 (this is httpd
ansible 192.168.10.202 -a systemctl restart httpd.service ansible 192.168.10.202 -a curl 192.168.10.202 ansible 192.168.10.202 -m shell -a echo this is httpd /var/www/html/index.html 11、systemd/service模块
name,设定管理服务的名称 statestarted]stopped|restarted 管理动作 enabledtrue 表示是否设置开机自启若果不加默认式开机不自启 runlevel配合enabled如果是开机自启可以设置运行级别。
对httpd开机自启设置
ansible 192.168.10.202 -m service -a enabledtrue namehttpd staterestarted 远程下载nginx访问页面设置成this is nginx并设置开机自启
安装nginx
ansible 192.168.10.202 -m yum -a namenginx启动nginx
ansible 192.168.10.202 -a systemctl restart nginx.service重定向输入this is nginx
ansible 192.168.10.202 -m shell -a echo this is nginx /usr/share/nginx/html/index.html访问页面
ansible 192.168.10.202 -a curl 192.168.10.202设置开机自启
ansible 192.168.10.202 -m service -a enabledtrue namenginx staterestarted12、script模块
运行本地脚本然后把结果输出到目标主机 写一个shell的脚本内容: touch 123 echo郭旗真帅” 123
vim test.sh
-------------------
echo 郭旗真帅 /opt/guoqi.txt
-------------------ansible all -m script -a test.shansible all -a cat /opt/guoqi.txt 13、setup模块
setup查看目标主机的环境系统(facts)目标节点的系统信息
获取环境信息
ansible 192.168.10.202 -m setup
查看IP地址
ansible all -m setup -a filter*ipv4
查看cpu信息
ansible all -m setup -a filteransible_facts
ansible all -m setup -a filter*processor
查看内存
ansible all -m setup -a filteransible_memory_mb
查看内核
ansible all -m setup -a filteransible_proc*
查看系统os信息 用的是什么系统
ansible all -m setup -a filter*os*
查看系统信息 用的是什么系统版本
ansible all -m setup -a filter*system*
查看硬盘
ansible all -m setup -a filteransible_dev*
主机清单
ansible可以管理上千台主机。 192.168.10.6[1:3] 管理61 62 63
主机清单管理组当中的变量名 ansible_host 连接时的ip地址 ansible_port 声明对方的连接端口默认是ssh的22端口。 ansible_user 指定连接时使用对方主机的用户名不指定主机ansible的用户即为使用目标主机的用户名 ansible_password 指定连接sshs时的密码(目标主机的用户密码) ansible_become 提升用户的权限改变用户身份 ansible_become root ansible_become_password 切换用户的密码免密钥的登录
vim /etc/ansible/ansible.cfg 设置免密钥对
vim /etc/ansible/ansible.cfg
71行 声明所有的用户、端口和密码 组嵌套
vim /etc/ansible/ansible.cfg