Run command on the Ansible host

后端 未结 8 1297
小鲜肉
小鲜肉 2020-12-22 14:45

Is it possible to run commands on the Ansible host?

My scenario is that I want to take a checkout from a git server that is hosted internally (and isn\'t accessible

8条回答
  •  萌比男神i
    2020-12-22 15:38

    You can use delegate_to to run commands on your Ansible host (admin host), from where you are running your Ansible play. For example:

    Delete a file if it already exists on Ansible host:

     - name: Remove file if already exists
       file:
        path: /tmp/logfile.log
        state: absent
        mode: "u+rw,g-wx,o-rwx"
       delegate_to: 127.0.0.1
    

    Create a new file on Ansible host :

     - name: Create log file
       file:
        path: /tmp/logfile.log
        state: touch
        mode: "u+rw,g-wx,o-rwx"
       delegate_to: 127.0.0.1
    

提交回复
热议问题