ansible -i hosts.ini -m setup <remote-host> ... "ansible_env": { ... "USER": "/home/remote-user01", ... "ansible_user_id": "remote-user01", ... "ansible_user_uid": 1000,
- set_fact: local_user_id: "{{ lookup('env','USER') }}" - name: create tmp dir local_action: module: file path: "/tmp/ansible-tmp" state: directory owne: "{{ local_user_id }}" become: false run_once: true
- name: list-hosted-zones local_action: shell aws --profile {{ aws_profile }} route53 list-hosted-zones --output json register: route53_result - set_fact: route53_hostedzone: "{{ (route53_result.stdout|from_json).HostedZones }}" - debug: var=route53_hostedzone
tasks: - name: Send summary mail local_action: module: mail subject: "Summary Mail" to: "{{ mail_recipient }}" body: "{{ mail_body }}" run_once: True
- hosts: localhost gather_facts: False tasks: - name: uptime local_action: command uptime register: result - debug: var=result
- hosts: localhost gather_facts: False tasks: - name: pwd local_action: shell echo $HOME register: result - debug: var=result.stdout
ansible-playbook -i hosts.ini -l localhost --sudo playbook.yml ... TASK: [debug var=result.stdout] *********************************************** ok: [127.0.0.1] => { "result.stdout": "/root" }