Re: [ansible-project] include_vars or vars_files in a role

2023-04-29 Thread Haji Hoare
Hi,

I think it would be a good idea to create a single role for managing ESXi 
settings, including changing the root password.
To make the role reusable, I recommend not specifying the hostname, ID, and 
password within the role itself.
In your playbook, you can utilize a `vars_files` directive to include a 
file like `vcenter_creds.yml` that contains definitions for variables such 
as `vcenter_hostname`.
These defined variables can then be accessed and used within your role as 
well.
In Ansible, variables defined within the role's vars/main.yml file have a 
higher precedence than those defined in the playbook.
Therefore, to ensure that the playbook-defined variables are used, avoid 
defining the same variables in the role's vars/main.yml file.



2023年4月26日水曜日 22:06:20 UTC+9 Tony Wong:

> any idea?
>
> On Tue, Apr 25, 2023 at 6:41 AM Tony Wong  wrote:
>
>> but how would i split up enable/disable ssh? can both be in same role? I 
>> need to enable ssh before i can change root pass, then disable ssh after 
>> its done
>>
>> On Tue, Apr 25, 2023 at 6:33 AM Dick Visser  wrote:
>>
>>> You could use ansible-galaxy to instantiate a role skeleton:
>>>
>>>
>>> dick.visser@GA0267 tmp$ ansible-galaxy init enable_ssh
>>> - Role enable_ssh was created successfully
>>> dick.visser@GA0267 tmp$ tree enable_ssh/
>>> enable_ssh/
>>> ├── README.md
>>> ├── defaults
>>> │   └── main.yml
>>> ├── files
>>> ├── handlers
>>> │   └── main.yml
>>> ├── meta
>>> │   └── main.yml
>>> ├── tasks
>>> │   └── main.yml
>>> ├── templates
>>> ├── tests
>>> │   ├── inventory
>>> │   └── test.yml
>>> └── vars
>>> └── main.yml
>>>
>>> 9 directories, 8 files
>>>
>>> btw, different roles to enable and disable SSH to me sounds like too 
>>> much overhead
>>>
>>>
>>>
>>> On Tue, 25 Apr 2023 at 15:16, Tony Wong  wrote:
>>>
 this is what i have currently

 change_esxi_root_pass

 ├── hosts

 ├── main.yml

 └── roles

 ├── change_esxi_root

 ├── disable_ssh

 └── enable_ssh

 ├── tasks

 │   └── main.yml

 └── vars

 ├── vars.yml

 └── vcenter_creds.yml





 On Tue, Apr 25, 2023 at 5:59 AM Tony Wong  wrote:

> for 
>
>   |__/defaults
> |
> |__/main
>  |__vcenter_creds.yml
>  |__vars.yml
>
>
> does these need to be under defaults under each role?
>
> what if other roles need to access these same vars files?
>
>
>
> On Mon, Apr 24, 2023 at 10:05 PM dulhaver via Ansible Project <
> ansible...@googlegroups.com> wrote:
>
>> the role structure can be as complex as mentioned in the previous 
>> post, but it does not have to include everything. In your case I'd say 
>> it 
>> boild down to this. 
>>   
>> you create a structure like this: 
>>   
>>   
>>   base_folder 
>>  | 
>>  |__ playbook.yml 
>>  | 
>>  |__ /roles 
>>| 
>>|__ role1 
>>  | 
>>  |__/tasks 
>>  | |__main.yml 
>>  | 
>>  |__/defaults
>> | 
>> |__/main 
>>  |__vcenter_creds.yml 
>>  |__vars.yml 
>>   
>> the playbook.yml 
>>   
>> - name: test 
>>   hosts: all 
>>   gather_facts: no 
>>   
>>   roles: 
>> - role1 
>>   
>> (there are other ways to all the roles though but thius should do the 
>> job) 
>>   
>>   
>>   
>> the ./tasks/main.yml 
>>   
>> --- 
>> - name: Enable SSH service 
>>   vmware_host_service_manager: 
>> hostname: “{{ vcenter_hostname }}” 
>> username: “{{ vcenter_username }}” 
>> password: “{{ vcenter_password }}” 
>> esxi_hostname: “{{ hostname }}” 
>> validate_certs: no 
>> state: present 
>> service_name: “TSM-SSH” 
>>   delegate_to: localhost 
>>   
>>
>>   
>>   
>>   
>>
>> On 04/24/2023 7:35 PM CEST Tony Wong  wrote: 
>>   
>>   
>> I got a pb that works like this. any idea how i can convert this to a 
>> role? 
>>   
>>
>>   
>>
>> ---
>>
>> - name: test
>>
>>   hosts: all
>>
>>   gather_facts: no
>>
>>   vars_files:
>>
>> - vcenter_creds.yml
>>
>> - vars.yml
>>
>>  
>>
>>   tasks:
>>
>>   - name: Enable SSH service
>>
>> vmware_host_service_manager:
>>
>>   hostname: "{{ vcenter_hostname }}"
>>
>>   username: "{{ vcenter_username }}"
>>

Re: [ansible-project] Configuring Ansible to prioritize a specific Python interpreter or automatically discover one

2023-04-29 Thread Haji Hoare
Thanks for your help and detailed explanation on the Python interpreter 
selection in Ansible. 

After our discussion, I confirmed that I can achieve my initial goal 
(prioritizing '/usr/bin/python3' when both '/usr/bin/python3' and 
'/usr/bin/python' are present, and automatically detecting other Python 
interpreters when '/usr/bin/python3' is not available) by adjusting the 
INTERPRETER_PYTHON setting.

Initially, I faced issues with the default behavior prioritizing 
'/usr/bin/python' when both were present. My environment is using Ansible 
2.10, which sets INTERPRETER_PYTHON to 'auto_legacy' by default. Based on 
your advice, I found that changing INTERPRETER_PYTHON to 'auto' or 
'auto_silent' resolved the issue in a straightforward manner.

I appreciate your assistance in resolving this problem. 

Best regards,

Haji

2023年4月29日土曜日 19:00:57 UTC+9 Vladimir Botka:

> On Sat, 29 Apr 2023 00:56:33 -0700 (PDT)
> Haji Hogson  wrote:
>
> > automatically discover the ... appropriate Python interpreter ...
> > /usr/bin/python3 if available ... and fall back to automatic
> > discovery otherwise.
>
> See the configuration parameter INTERPRETER_PYTHON_FALLBACK
>
> https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python-fallback
>
> You can put it into the inventory file
> ansible_interpreter_python_fallback=['/usr/bin/python3','/usr/bin/python']
>
> See also the configuration parameter INTERPRETER_PYTHON
>
> https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python
>
> The fallback will be used if INTERPRETER_PYTHON is not available.
> "The fallback behavior will issue a warning that the interpreter
> should be set explicitly..." You can chose a discovery mode (default
> auto).
>
>
> -- 
> Vladimir Botka
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e23d9aaa-65f2-4102-9bf2-c08c4906244bn%40googlegroups.com.


Re: [ansible-project] Configuring Ansible to prioritize a specific Python interpreter or automatically discover one

2023-04-29 Thread Vladimir Botka
On Sat, 29 Apr 2023 00:56:33 -0700 (PDT)
Haji Hogson  wrote:

> automatically discover the ... appropriate Python interpreter ...
> /usr/bin/python3 if available ... and fall back to automatic
> discovery otherwise.

See the configuration parameter INTERPRETER_PYTHON_FALLBACK
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python-fallback

You can put it into the inventory file
ansible_interpreter_python_fallback=['/usr/bin/python3','/usr/bin/python']

See also the configuration parameter INTERPRETER_PYTHON
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python

The fallback will be used if INTERPRETER_PYTHON is not available.
"The fallback behavior will issue a warning that the interpreter
should be set explicitly..." You can chose a discovery mode (default
auto).


-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230429120033.54c13e8c%40gmail.com.


pgphg99Ugi820.pgp
Description: OpenPGP digital signature


[ansible-project] Configuring Ansible to prioritize a specific Python interpreter or automatically discover one

2023-04-29 Thread Haji Hogson
Hi,

I'd like to ask for advice on configuring Ansible to prioritize using a 
specific Python interpreter if it exists or automatically discover the 
appropriate Python interpreter if the preferred one is not present, 
especially in cases where the preferred interpreter does not exist 
initially. As an example, I want to install and use /usr/bin/python3 in an 
environment where only /usr/bin/python exists by default.

Ideally, I would like to define this behavior in the inventory file 
(inventory.ini), so that Ansible would use /usr/bin/python3 if available, 
and fall back to automatic discovery otherwise.

How can I achieve this? Are there any recommended configurations or best 
practices for this scenario?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/177b2f57-724e-482d-a688-c5c3f85f84e9n%40googlegroups.com.