修改hosts文件位置html
vi /etc/ansible/ansible.cfg inventory = /etc/ansible/hosts
默認/etc/ansible/hosts
python
例子linux
[greenplum] mdw ansible_ssh_host=1.1.1.1 ansible_connection=ssh ansible_ssh_user=root ansible_python_interpreter=/usr/bin/python ansible_ssh_pass=123 sdw1 ansible_ssh_host=1.1.1.2 ansible_connection=ssh ansible_ssh_user=root ansible_python_interpreter=/usr/bin/python ansible_ssh_pass=123 sdw2 ansible_ssh_host=1.1.1.3 ansible_connection=ssh ansible_ssh_user=root ansible_python_interpreter=/usr/bin/python ansible_ssh_pass=123
[databases] some_host ansible_ssh_port=2222 ansible_ssh_user=manager aws_host ansible_ssh_private_key_file=/home/example/.ssh/aws.pem [webservers] freebsd_host ansible_python_interpreter=/usr/local/bin/python ruby_module_host ansible_ruby_interpreter=/usr/bin/ruby.1.9.3
配置項web
ansible_ssh_host 將要鏈接的遠程主機名.與你想要設定的主機的別名不一樣的話,可經過此變量設置. ansible_ssh_port ssh端口號.若是不是默認的端口號,經過此變量設置. ansible_ssh_user 默認的 ssh 用戶名 ansible_ssh_pass ssh 密碼(這種方式並不安全,咱們強烈建議使用 --ask-pass 或 SSH 密鑰) ansible_sudo_pass sudo 密碼(這種方式並不安全,咱們強烈建議使用 --ask-sudo-pass) ansible_sudo_exe (new in version 1.8) sudo 命令路徑(適用於1.8及以上版本) ansible_connection 與主機的鏈接類型.好比:local, ssh 或者 paramiko. Ansible 1.2 之前默認使用 paramiko.1.2 之後默認使用 'smart','smart' 方式會根據是否支持 ControlPersist, 來判斷'ssh' 方式是否可行. ansible_ssh_private_key_file ssh 使用的私鑰文件.適用於有多個密鑰,而你不想使用 SSH 代理的狀況. ansible_shell_type 目標系統的shell類型.默認狀況下,命令的執行使用 'sh' 語法,可設置爲 'csh' 或 'fish'. ansible_python_interpreter 目標主機的 python 路徑.適用於的狀況: 系統中有多個 Python, 或者命令路徑不是"/usr/bin/python",好比 \*BSD, 或者 /usr/bin/python 不是 2.X 版本的 Python.咱們不使用 "/usr/bin/env" 機制,由於這要求遠程用戶的路徑設置正確,且要求 "python" 可執行程序名不可爲 python之外的名字(實際有可能名爲python26). 與 ansible_python_interpreter 的工做方式相同,可設定如 ruby 或 perl 的路徑....
linkshell
ansible gp -m authorized_key -a "user=root key={{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html#authorized-key-module安全
ansible gp -m selinux -a "state=disabled"
https://docs.ansible.com/ansible/latest/modules/selinux_module.html#examplesruby