在系统创建的时候,我们可能需要为所有的服务器创建一个些管理员帐号
1 2 3 |
- zhang3 - li4 - wang5 |
这些用户是所有的服务器都需要的,所以我们一般直接写一个Playbook 写上 – hosts: all 但是,有时候,我们不光需要创建通用的用户,我们还需要为某些特殊的服务器创建特有……
我们在日常的工作中经常会遇到需要修改配置文件中某个项的值的情况,什么apache啊,mysql啊,docker 啊, 等等 ,当然我们可以使用template等其它方式来实现,但是今天我们要说一下这个lineinfile的正则替换,聚个例子来说,docker的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# /etc/sysconfig/docker # Modify these options if you want to change the way the docker daemon runs OPTIONS='--selinux-enabled' DOCKER_CERT_PATH=/etc/docker # If you want to add your own registry to be used for docker search and docker # pull use the ADD_REGISTRY option to list a set of registries, each prepended # with --add-registry flag. The first registry added will be the first registry # searched. ADD_REGISTRY='--add-registry registry.access.redhat.com' # If you want to block registries from being used, uncomment the BLOCK_REGISTRY # option and give it a set of registries, each prepended with --block-registry # flag. For example adding docker.io will stop users from downloading images # from docker.io # BLOCK_REGISTRY='--block-registry' # If you have a registry secured with https but do not have proper certs # distributed, you can tell docker to not look for full authorization by # adding the registry to the INSECURE_REGISTRY line and uncommenting it. # INSECURE_REGISTRY='--insecure-registry' # On an SELinux system, if you remove the --selinux-enabled option, you # also need to turn on the docker_transition_unconfined boolean. # setsebool -P docker_transition_unconfined 1 # Location used for temporary files, such as those created by # docker load and build operations. Default is /var/lib/docker/tmp # Can be overriden by setting the following environment variable. # DOCKER_TMPDIR=/var/tmp # Controls the /etc/cron.daily/docker-logrotate cron job status. # To disable, uncomment the line below. # LOGROTATE=false |
其中……
先上官网文档地址:http://docs.ansible.com/ansible/copy_module.html copy模块的坐拥其实就是 将某个文件拷贝到远程主机上,比如,我们本机有个脚本需要在远程主机执行一下,第一步肯定是拷贝过去 例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Example from Ansible Playbooks - copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644 # The same example as above, but using a symbolic mode equivalent to 0644 - copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode="u=rw,g=r,o=r" # Another symbolic mode example, adding some permissions and removing others - copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode="u+rw,g-wx,o-rwx" # Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version - copy: src=/mine/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=644 backup=yes # Copy a new "sudoers" file into place, after passing validation with visudo - copy: src=/mine/sudoers dest=/etc/sudoers validate='visudo -cf %s' |
当然,正如官方文档上介绍,……