Ansible - iventory

  1. Outline
    1. Simple ansible
  2. ready
    1. ansible installation
    2. Avoid close Login
  3. Promise
    1. Because the focus is on iventory, so only the most simple ping module

1. host-simple

  1. Outline
    1. Simple version of the hosts file
  2. hosts
    1. Not the / etc / hosts
      1. ansible script, very often, the host needs of the environment
      2. If the configuration / etc / hosts
        1. not very convenient
        2. I can not go along with the script
  3. format

    # hosts-simple
    192.168.20.135.nip.io ansible_user=root
  4. command

    #  ansible -i <hosts> <hosts/group> -m <module> 
    >  ansible -i hosts-simple 192.168.20.135.nip.io -m ping 
  5. doubt
    1. nip.io
      1. This thing in the end is what

2. hosts

  1. Outline
    1. hosts file similar systems
  2. File Structure
    1. Host name, address
      1. format

        <hostName> ansible_host=<ip>
      2. problem
        1. ansible_host just a property
          1. There are other attributes you
    2. Clusters
      1. Outline
        1. It can be introduced to multiple addresses
      2. format

        [groupName]
        <hostName>
        <hostName>
    3. Large clusters
      1. Outline
        1. Clusters can continue to set
      2. format

        [superGrouop:subGroup]
        <group>
        <group>
    4. Attributes
      1. Outline
        1. Group as a unit, the division of property
      2. format

        [group:vars]
        <key>=<value>
      3. doubt
        1. I do not know there is no inheritance relationship
    5. Examples

      # 1. 服务器
      demo ansible_host=192.168.2.135
      
      # 2. 服务器组
      [servers]
      demo
      
      # 3. 大组
      [cloud:children]
      servers
      
      # 4. 变量
      [cloud:vars]
      ansible_connection=ssh
      ansible_user=root
      ansible_private_key_file=~/.ssh/id_rsa
      host_key_checking=True
  3. ansible command: Specify the host file
    1. default
      1. /etc/ansible/hosts
    2. parameter

      -i <hosts>

2. ping module

  1. Outline
    1. ansible functions are implemented by the module
    2. ping module, so naturally it is to achieve ping function
  2. parameter

    -m <module>

3. Packet execution

  1. Outline
    1. Execution of the script size, can be specified
  2. command

    # 1. 地址对
    > ansible -i hosts demo -m ping
    # 2. 组
    > ansible -i hosts servers -m ping
    # 3. 大组
    > ansible -i hosts cloud -m ping
    # 4. 所有
    > ansible -i hosts all -m ping
    

ps

  1. ref
    1. learn python
    2. Ansible series (a): Basic configuration and usage
  2. Legacy
    1. Because it is a novice, so that many parameters are not well understood, and so your studies will be finished up

Guess you like

Origin www.cnblogs.com/xy14/p/11572682.html