how to run a particular task on specific host in ansible

前端 未结 3 1026
遥遥无期
遥遥无期 2021-01-07 16:40

my inventory file\'s contents -

[webservers]
x.x.x.x ansible_ssh_user=ubuntu

[dbservers]
x.x.x.x ansible_ssh_user=ubuntu

in my tasks file

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 17:32

    Thank you, this helps me too.

    hosts file:

    [production]
    host1.dns.name
    
    [internal]
    host2.dns.name
    

    requirements.yml file:

    - name: install the sphinx-search rpm from a remote repo on x86_64 - internal host
      when: inventory_hostname in groups['internal']
      yum:
        name: http://sphinxsearch.com/files/sphinx-2.2.11-1.rhel7.x86_64.rpm
        state: present
    
    - name: install the sphinx-search rpm from a remote repo on i386 - Production
      when: inventory_hostname in groups['production']
      yum:
        name: http://sphinxsearch.com/files/sphinx-2.2.11-2.rhel6.i386.rpm
        state: present
    

提交回复
热议问题