技巧

来源:互联网 发布:激光雕刻用什么软件 编辑:程序博客网 时间:2024/04/28 07:34

cron计划任务模块的使用

tasks:
- cron: name="check dirs" hour="5,2" job="ls -alh > /dev/null"
- name: create {{ user }} on web                             
  user: name="{{ user }}"

执行可选择的tag

ansible-playbook test2.yml --tags="play1,play3" 

跳过执行的tag

ansible-playbook site.yml -i hosts  -c ssh --skip-tags="common,jdk"

开启路由转发功能

- sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes

创建ssh key

user: name=jsmith generate_ssh_key=yes ssh_key_bits=2048

添加一个用户,shell环境指定到/bin/bash 

- user: name=james shell=/bin/bash groups=admins,developers append=yes

删除一个用户

- user: name=johnd state=absent remove=yes

动态添加host

add host to group 'just_created' with variable foo=42
- add_host: name={{ ip_from_ec2 }} groups=just_created foo=42

add a host with a non-standard port local to your machines
- add_host: name={{ new_ip }}:{{ new_port }}

add a host alias that we reach through a tunnel
- add_host: hostname={{ new_ip }}
            ansible_ssh_host={{ inventory_hostname }}
            ansible_ssh_port={{ new_port }}

单个执行一条命令

ansible -i ~/hosts all -a 'who'

linux下安装部署

http://haohaozhang.blog.51cto.com/9176600/1610499


0 0
原创粉丝点击