ansible中主要使用的模块:
1.fail模块
- fail:
msg: "!!!!"
when: ....
一般搭配when使用,当when条件符合时,整个过程终端,打印msg
2.debug模块
- debug:
msg: var=....
一般进行调试,可以查看变量值,或者查看正则表达式
3.command模块
- command:
date -s "{{std_date.stdout}}"
4.user模块
- user:
name: root
state: present
password:
update_password: always
管理远程主机,state为present,需要该用户存在
5.lineinfile模块
- lineinfile:
line: ""
dest: /etc/sudoers
state: present
确保dest文件中,存在line的内容
6.authoried_key模块
- authorized_key:
user: root
key: "{{ lookup('file', '/id_rsa.pub') }}"
state: present
这段代码是指该路径中存在公钥文件,为了减少麻烦,一般的流程自己安装包中配置公钥以及私钥,然后将其发往所有主机,就不需要在主机中复制了
7.file模块
- file:
path: "/home/{{ }}/.ssh"
owner: "{{ }}"
group: "{{ }}"
state: directory
建立文件,类型为目录,可以表明属主和属组
8.copy模块
- copy:
src: /{{ item }}
dest: "/home/{{ }}/.ssh/{{ item }}"
mode: 0600
owner: "{{ }}"
group: "{{ }}"
with_items:
- id_rsa.pub
- id_rsa
复制文件到节点,并表明权限为600,标注属主和属组
9.yum模块
- yum:
name: "/tmp/rsync-3.1.2-4.el7.x86_64.rpm"
state: installed
安装rsync
10.synchronize模块
- synchronize:
src: "files/bin"
dest: "{{ project_path }}/"
copy_links: yes
同步文件,同时复制链接