Last active
April 16, 2023 01:40
-
-
Save moreati/36eb8d4143505d2e7ea641a61f00545c to your computer and use it in GitHub Desktop.
Playing Guess Who with Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host rpi1 | |
HostName raspberrypi1.local | |
User pi | |
Host rpi2 | |
HostName raspberrypi2.local | |
User pi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
hosts: | |
rpi1: | |
rpi2: | |
ansible_user: pi | |
vars: | |
ansible_become_method: sudo | |
ansible_python_interpreter: python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook -i inventory.yml playbook.yml | |
PLAY [whoami, play level become=false] **************************************************************************************************************************************************************************************************** | |
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************** | |
ok: [rpi2] | |
ok: [rpi1] | |
TASK [become=false,ansible_user] ********************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_user: VARIABLE IS NOT DEFINED! | |
ok: [rpi2] => | |
ansible_user: pi | |
TASK [become=false,ansible_facts.user_id] ************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
ansible_facts.user_id: pi | |
ok: [rpi2] => | |
ansible_facts.user_id: pi | |
TASK [become=false,ansible_facts.env.USER] ************************************************************************************************************************************************************************************************ | |
ok: [rpi1] => | |
ansible_facts.env.USER: pi | |
ok: [rpi2] => | |
ansible_facts.env.USER: pi | |
TASK [become=false,lookuo(whoami)] ******************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
msg: alex | |
ok: [rpi2] => | |
msg: alex | |
TASK [become=true,ansible_user] *********************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_user: VARIABLE IS NOT DEFINED! | |
ok: [rpi2] => | |
ansible_user: pi | |
TASK [become=true,ansible_facts.user_id] ************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_facts.user_id: pi | |
ok: [rpi2] => | |
ansible_facts.user_id: pi | |
TASK [become=true,ansible_facts.env.USER] ************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
ansible_facts.env.USER: pi | |
ok: [rpi2] => | |
ansible_facts.env.USER: pi | |
TASK [become=true,lookuo(whoami)] ********************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
msg: alex | |
ok: [rpi2] => | |
msg: alex | |
PLAY [whoami, play level become=true] ***************************************************************************************************************************************************************************************************** | |
TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************** | |
ok: [rpi2] | |
ok: [rpi1] | |
TASK [become=false,ansible_user] ********************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_user: VARIABLE IS NOT DEFINED! | |
ok: [rpi2] => | |
ansible_user: pi | |
TASK [become=false,ansible_facts.user_id] ************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
ansible_facts.user_id: root | |
ok: [rpi2] => | |
ansible_facts.user_id: root | |
TASK [become=false,ansible_facts.env.USER] ************************************************************************************************************************************************************************************************ | |
ok: [rpi1] => | |
ansible_facts.env.USER: root | |
ok: [rpi2] => | |
ansible_facts.env.USER: root | |
TASK [become=false,lookuo(whoami)] ******************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
msg: alex | |
ok: [rpi2] => | |
msg: alex | |
TASK [become=true,ansible_user] *********************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_user: VARIABLE IS NOT DEFINED! | |
ok: [rpi2] => | |
ansible_user: pi | |
TASK [become=true,ansible_facts.user_id] ************************************************************************************************************************************************************************************************** | |
ok: [rpi1] => | |
ansible_facts.user_id: root | |
ok: [rpi2] => | |
ansible_facts.user_id: root | |
TASK [become=true,ansible_facts.env.USER] ************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
ansible_facts.env.USER: root | |
ok: [rpi2] => | |
ansible_facts.env.USER: root | |
TASK [become=true,lookuo(whoami)] ********************************************************************************************************************************************************************************************************* | |
ok: [rpi1] => | |
msg: alex | |
ok: [rpi2] => | |
msg: alex | |
PLAY RECAP ******************************************************************************************************************************************************************************************************************************** | |
rpi1 : ok=18 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | |
rpi2 : ok=18 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | |
$ ansible-playbook --version | |
ansible-playbook 2.9.11 | |
config file = /home/alex/.ansible.cfg | |
configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] | |
ansible python module location = /home/alex/venv/lib/python3.8/site-packages/ansible | |
executable location = /home/alex/venv/bin/ansible-playbook | |
python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: whoami, play level become=false | |
hosts: rpi1,rpi2 | |
become: false | |
tasks: | |
- {name: "become=false,ansible_user", become: false, debug: {var: ansible_user}} | |
- {name: "become=false,ansible_facts.user_id", become: false, debug: {var: ansible_facts.user_id}} | |
- {name: "become=false,ansible_facts.env.USER", become: false, debug: {var: ansible_facts.env.USER}} | |
- {name: "become=false,lookuo(whoami)", become: false, debug: {msg: "{{ lookup('lines', 'whoami') }}"}} | |
- {name: "become=true,ansible_user", become: true, debug: {var: ansible_user}} | |
- {name: "become=true,ansible_facts.user_id", become: true, debug: {var: ansible_facts.user_id}} | |
- {name: "become=true,ansible_facts.env.USER", become: true, debug: {var: ansible_facts.env.USER}} | |
- {name: "become=true,lookuo(whoami)", become: true, debug: {msg: "{{ lookup('lines', 'whoami') }}"}} | |
- name: whoami, play level become=true | |
hosts: rpi1,rpi2 | |
become: true | |
tasks: | |
- {name: "become=false,ansible_user", become: false, debug: {var: ansible_user}} | |
- {name: "become=false,ansible_facts.user_id", become: false, debug: {var: ansible_facts.user_id}} | |
- {name: "become=false,ansible_facts.env.USER", become: false, debug: {var: ansible_facts.env.USER}} | |
- {name: "become=false,lookuo(whoami)", become: false, debug: {msg: "{{ lookup('lines', 'whoami') }}"}} | |
- {name: "become=true,ansible_user", become: true, debug: {var: ansible_user}} | |
- {name: "become=true,ansible_facts.user_id", become: true, debug: {var: ansible_facts.user_id}} | |
- {name: "become=true,ansible_facts.env.USER", become: true, debug: {var: ansible_facts.env.USER}} | |
- {name: "become=true,lookuo(whoami)", become: true, debug: {msg: "{{ lookup('lines', 'whoami') }}"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment