Tag: ansible

  • ansible-fetch获取服务器上的文件

    目标是获取两台服务器下root,www用户的crontab文件,并保存在本地的fetched目录。

    main.yml文件如下

    – hosts: all
    tasks:
    – fetch: src=/var/spool/cron/www dest=fetched/cron-www-{{ ansible_hostname }} flat=yes

    – fetch: src=/var/spool/cron/root dest=fetched/cron-root-{{ ansible_hostname }} flat=yes

    执行完之后的目录结构如下

    [[email protected] fetch-crontab]# tree
    .
    ├── fetched
    │   ├── cron-root-2.jpuyy.com
    │   └── cron-www-1.jpuyy.com
    ├── hosts
    └── main.yml

  • ansible使用笔记-改主机名

    针对所有主机修改主机名

    - hosts: all
     hostname: name={{ hostname }}