0

Hi can i know i have the below main playbook and inbside the role folder for file-transfer and deployment i have task. I would like to know below

1) what happen if task in file-transfer failed? will task at the deployment role execute or will it fail as well? 2) how can i have 1 place where to save the location of the the deployment folder as it will be common for both roles file-transfer and deployment 3) in file-transfer role i need transfer from 1 remote sever to another remote server. I found there is a copy module but how can i refer from another remote server copy to web-server ip?

- hosts: web-server
  user: deploymentusr
  roles:
    - file-transfer
    - deployment

1 Answers1

0

To answer all your questions :

1) what happen if task in file-transfer failed? will task at the deployment role execute or will it fail as well?

Ansible playbook will fail if any of the play fails during execution. However, this can be overridden by ignore_errors: yes.

Refer : https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html

2) how can i have 1 place where to save the location of the the deployment folder as it will be common for both roles file-transfer and deployment

Since you need something common between 2 roles, you can use role-specific variable. If you need this to be host-specific, use host or group variables. Basically, use a variable based on the scope of requirement.

3) in file-transfer role i need transfer from 1 remote sever to another remote server. I found there is a copy module but how can i refer from another remote server copy to web-server ip?

You can use synchronize module with delegate option to copy from remote-to-remote.

Refer this SO answer : How to copy files between two nodes using ansible

Refer synchronize module here : https://docs.ansible.com/ansible/latest/modules/synchronize_module.html

saurabh14292
  • 1,281
  • 2
  • 10
  • 12
  • hi thanks. for role-specific / host-specific variable do you have any example i can refer to as i could not find role-specific or host-specific module in ansible doc – soft developer May 15 '20 at 16:22
  • There's no role-specific/host-specific module. What I said was using variables either on playbook level or on host/inventory level. Since you need to have a path (which can be a variable) across multiple roles (or across hosts), you should host/group variables. Have a look at this : https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#defining-variables-in-a-playbook – saurabh14292 May 18 '20 at 06:00
  • Checkout "Variable precedence: Where should I put a variable?" on the above link. – saurabh14292 May 18 '20 at 06:01
  • A complement for question 1) : Ansible playbook will fail if any of the play fails, yes, but only for the failed hosts. In the example, if web-server is a group of hosts, the playbook continue for each host without fail. – Jacquelin Ch Aug 29 '20 at 18:33