[ansible-project] Ansible can't sudo to unprivileged user

2022-12-01 Thread dutu.a...@gmail.com
Hello,

I have a use case where ansible has to connect with an automation user, 
which is deployed on all the servers, and the sudo to a service user that 
runs on that particular machine. The service users are all different 
between these machines and are unprivileged users.

So ansible is having a issue with that. I just tried to do a whoami using 
the shell module, for a simple test.
I get back: Shared connection closed.

Setfacl is installed and POSIX acls are available. I tested and as the 
connection user I could add an rw acl for the service user. So ansible 
should be able to do it. 

These users also share a group so I tried setting 
ansible_common_remote_group. It didn't help.
I tried setting allow_world_readable_tmpfiles. That didn't help either.

So I am a bit at a loss here. By all means, it seems this should work, but 
for some reason it doesn't and I'm not sure what to check next.

Best regards,
Adrian

-- 
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/28b63ec0-f54e-4b53-92f7-7280b767e764n%40googlegroups.com.


Re: [ansible-project] Ansible Expect - Program under control has same prompt

2022-12-01 Thread Dick Visser
Then i don't know, perhaps someone else does

On Fri, 2 Dec 2022 at 03:00, phillip.from.oz 
wrote:

> Thanks.
>
> I tried what you suggested but I get:
> 'responses' is of type  and we were unable to convert to dict
>
> But this seems to work:
>  responses:
> Username: sq
> Password: "SoLong>"
> BASE\>:
>   -  "w ##Class(websys).test()"
>   -  "H"
>
> On Thursday, December 1, 2022 at 8:26:08 PM UTC+11 dnmv...@gmail.com
> wrote:
>
>> Hi
>>
>> It now partly works because you made the items of a single dict key into
>> a list and by doing so also quoted the value with '#' in it.
>> But what I meant is to have the responses itself be a list, so you can
>> have duplicates. I think this would look like:
>>
>> responses:
>>   - Username: sq
>>   - Password: "SoLong>"
>>   - BASE\>: "w ##Class(websys).test()"
>>   - BASE\>: "H"
>>   - BASE1>: "foo"
>>   - BASE1>: "bar"
>>   - BASE1>: "bz"
>>   - BASE2>: "fog"
>>   - BASE2>: "fbzhy33"
>>   - BASE1>: "bar"
>>
>>
>> etc
>>
>>
>>
>> On Wed, 30 Nov 2022 at 21:55, phillip.from.oz 
>> wrote:
>>
>>> Thanks. That did the trick.
>>>
>>> I changed
>>> BASE\>: w ##Class(websys).test()
>>> BASE\>: H
>>> to
>>> BASE\>: ["w ##Class(websys.PatchHistory).test()","H"]
>>>
>>> However, how do I code the list if I have this set of prompts:
>>> BASE1>
>>> BASE1>
>>> BASE1>
>>> BASE2>
>>> BASE2>
>>> BASE1>
>>> BASE1>
>>> On Wednesday, November 30, 2022 at 4:02:42 PM UTC+11 dnmv...@gmail.com
>>> wrote:
>>>
 Your responses is now a dict which cannot have the same key more than
 once. So the second BASE question isn't going to work.
 Try turning it into a list.
 See
 https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html#examples




 On Wed, 30 Nov 2022 at 02:03, phillip.from.oz 
 wrote:

> Hi,
> I want to run a program on a remote server where after login, the
> program will ask for more input using the same prompt.
>
> This is the basic flow:
> Read Username
> Read Password
> Read commands <- these get echoed back
> until 'h' or 'H' is entered
>
> This is a sample run of the program
> BASE:/home# python3 converse2.py
> Welcome to BASE
>My configuration is up to date
>Print settings are normal
>  Username: sq
>  Password: SoLong>
> BASE>w abc
> w abc
> BASE>h
>
> I run the same program using Ansible Expect with this playbook:
> ---
> - name: Test a conversation
>hosts: BASE
>remote_user: root
>gather_facts: false
>tasks:
> - name: Copy script converse2.py
>   copy: src=/home/converse2.py
>  dest=/home/converse2.py
>  remote_src=no
>  mode=preserve
> - name: Run test session
>   expect:
>  echo: yes
>  chdir: /tmp
>  command: python3 /home/converse2.py
>  timeout: "300"
>  responses:
>  Username: sq
>  Password: "SoLong>"
>  BASE\>: w ##Class(websys).test()
>  BASE\>: H
>  register: command_output
> - debug:
>   msg: "{{ command_output.stdout.split('\n') }}"
>
> However Ansible Expect is not sending 'w ##Class(websys).test()' to
> the program
>
> This is the run:
> ansible-playbook /home/ansible_playbooks/test-converse2.yml
> [WARNING]: While constructing a mapping from
> /home/ansible_playbooks/test-converse2.yml, line 20, column 9, found a
> duplicate dict key (BASE\>). Using last defined value only.
>
> PLAY [Test a conversation]
> 
>
> TASK [Copy script converse2.py]
> ***
> ok: [TRAK-BASE01]
>
> TASK [Run test session]
> 
> changed: [TRAK-BASE01]
>
> TASK [debug]
> 
> ok: [TRAK-BASE01] => {
> "msg": [
> "\r",
> "Welcome to BASE\r",
> "   My configuration is up to date\r",
> "   Print settings are normal\r",
> "\r",
> "\r",
> "Username: sq\r",
> "Password: SoLong>\r",
> "BASE>H"
> ]
> }
>
> PLAY RECAP
> 

[ansible-project] Ansible Expect - delaybeforesend how to set

2022-12-01 Thread phillip.from.oz
Hi,
I undestand that 'Ansible Expect' uses python pexpect.

Do you know if ansible playbook can change pexpect's 'delaybeforesend'?

' delaybeforesend' is used to wait a little time before sending a response 
to a prompt.
The reason for this sometimes my Ansible Expect playbook works and 
sometimes the same playbook fails. I think this is a timing issue when the 
program on the remote side is a bit slow.


-- 
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/32df90f6-35dd-4659-93ee-59ff802f4fcen%40googlegroups.com.


Re: [ansible-project] Ansible Expect Prompt set to a variable in Host not working

2022-12-01 Thread Phillip Wu
Thanks

That's a pity.

The prompt is different on each host that I'll be adding (later)

On Fri, Dec 2, 2022 at 1:37 AM Matt Martz  wrote:

> Generally speaking, you cannot set keys anywhere in ansible to a template,
> this is simply just not allowed.
>
> As such, there really isn't a mechanism for doing this.  Keys must be
> hardcoded.
>
> On Thu, Dec 1, 2022 at 3:15 AM phillip.from.oz 
> wrote:
>
>> Hi,
>> I'm trying to set Ansible Expect prompt to a variable in host file.
>>
>> However this does not work.
>>
>> You can see that Ansible is not sending a response to the prompt.
>> The prompt is defined as the contents of a variable declared in host file.
>>
>> Can someone see what is wrong?
>>
>> ===
>> This is the host file:
>> [trak]
>> BASE prompt="BASE\>"
>>
>> This is the Ansible playbook:
>> ---
>> - name: Test a conversation
>>   hosts: BASE
>>   remote_user: root
>>   gather_facts: false
>>
>>   tasks:
>>   - name: Copy script converse.py
>> copy: src=/home/converse.py
>> dest=/home/converse.py
>> remote_src=no
>> mode=preserve
>>   - name: Run test session
>> expect:
>>   echo: yes
>>   chdir: /tmp
>>   command: python3 /home/converse.py
>>   timeout: "300"
>>   responses:
>> Username: sq
>> Password: "MeMe"
>> "{{hostvars[inventory_hostname].prompt}}": ["w
>> ##Class(websys).test()","H"]
>> register: command_output
>>   - debug:
>>   msg: "{{ command_output.stdout.split('\n') }}"
>>
>>
>>
>>
>> This is the result:
>> # ansible-playbook test-converse.yml
>>
>> PLAY [Test a conversation]
>> 
>>
>> TASK [Copy script converse.py]
>> 
>> changed: [BASE]
>>
>> TASK [Run test session]
>> ***
>> fatal: [BASE]: FAILED! =>
>>{"changed": true, "cmd": "python3 converse.py", "delta":
>> "0:05:00.340507",
>> "end": "2022-12-01 19:12:18.727066", "msg": "command
>> exceeded timeout",
>> "rc": null, "start": "2022-12-01 19:07:18.386559",
>> "stdout": "\r\nWelcome to BASE\r\n   My configuration is
>> up to date\r\n
>>Print settings are normal\r\n\r\n\r\n
>> Username: sq\r\n
>> Password: MeMe\r\n
>> BASE>",
>> "stdout_lines": ["", "Welcome to BASE", "   My
>> configuration is up to date",
>> "   Print settings are normal", "", "",
>> "Username: sq", "Password: MeMe", "BASE>"]}
>>
>> PLAY RECAP
>> **
>> BASE : ok=1changed=1unreachable=0failed=1skipped=0
>>  rescued=0ignored=0
>>
>> --
>> 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/e8b0cfe2-6704-45db-b87c-68da18ba4e94n%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Matt Martz
> @sivel
> sivel.net
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/-rdOecvL51w/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAD8N0v9ts_6KwDRWQgjW4wEknNNkwo_1WSSPFv4JdjER9_zftg%40mail.gmail.com
> 
> .
>

-- 
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/CAJVgDZa6QFO2L%2BshC3_i%3DvbVFAJ2W7OHM%2BuFWecm6_a02SohLg%40mail.gmail.com.


Re: [ansible-project] Ansible Expect - Program under control has same prompt

2022-12-01 Thread phillip.from.oz
Thanks.

I tried what you suggested but I get:
'responses' is of type  and we were unable to convert to dict

But this seems to work:
 responses:
Username: sq
Password: "SoLong>"
BASE\>:
  -  "w ##Class(websys).test()"
  -  "H"

On Thursday, December 1, 2022 at 8:26:08 PM UTC+11 dnmv...@gmail.com wrote:

> Hi
>
> It now partly works because you made the items of a single dict key into a 
> list and by doing so also quoted the value with '#' in it.
> But what I meant is to have the responses itself be a list, so you can 
> have duplicates. I think this would look like:
>
> responses:
>   - Username: sq
>   - Password: "SoLong>"
>   - BASE\>: "w ##Class(websys).test()"
>   - BASE\>: "H"
>   - BASE1>: "foo"
>   - BASE1>: "bar"
>   - BASE1>: "bz"
>   - BASE2>: "fog"
>   - BASE2>: "fbzhy33"
>   - BASE1>: "bar"
>
>
> etc
>
>
>
> On Wed, 30 Nov 2022 at 21:55, phillip.from.oz  
> wrote:
>
>> Thanks. That did the trick.
>>
>> I changed
>> BASE\>: w ##Class(websys).test()
>> BASE\>: H
>> to
>> BASE\>: ["w ##Class(websys.PatchHistory).test()","H"]
>>
>> However, how do I code the list if I have this set of prompts:
>> BASE1>
>> BASE1>
>> BASE1>
>> BASE2>
>> BASE2>
>> BASE1>
>> BASE1>
>> On Wednesday, November 30, 2022 at 4:02:42 PM UTC+11 dnmv...@gmail.com 
>> wrote:
>>
>>> Your responses is now a dict which cannot have the same key more than 
>>> once. So the second BASE question isn't going to work.
>>> Try turning it into a list.
>>> See 
>>> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html#examples
>>>
>>>
>>>
>>>
>>> On Wed, 30 Nov 2022 at 02:03, phillip.from.oz  
>>> wrote:
>>>
 Hi,
 I want to run a program on a remote server where after login, the 
 program will ask for more input using the same prompt.

 This is the basic flow:
 Read Username
 Read Password
 Read commands <- these get echoed back
 until 'h' or 'H' is entered

 This is a sample run of the program
 BASE:/home# python3 converse2.py
 Welcome to BASE
My configuration is up to date
Print settings are normal
  Username: sq
  Password: SoLong> 
 BASE>w abc
 w abc
 BASE>h

 I run the same program using Ansible Expect with this playbook:
 --- 
 - name: Test a conversation
hosts: BASE
remote_user: root
gather_facts: false
tasks:
 - name: Copy script converse2.py
   copy: src=/home/converse2.py
  dest=/home/converse2.py
  remote_src=no
  mode=preserve 
 - name: Run test session
   expect:
  echo: yes
  chdir: /tmp
  command: python3 /home/converse2.py
  timeout: "300"
  responses:
  Username: sq
  Password: "SoLong>"
  BASE\>: w ##Class(websys).test()
  BASE\>: H
  register: command_output
 - debug:
   msg: "{{ command_output.stdout.split('\n') }}"

 However Ansible Expect is not sending 'w ##Class(websys).test()' to the 
 program

 This is the run:
 ansible-playbook /home/ansible_playbooks/test-converse2.yml
 [WARNING]: While constructing a mapping from 
 /home/ansible_playbooks/test-converse2.yml, line 20, column 9, found a 
 duplicate dict key (BASE\>). Using last defined value only.

 PLAY [Test a conversation] 
 

 TASK [Copy script converse2.py] 
 ***
 ok: [TRAK-BASE01]

 TASK [Run test session] 
 
 changed: [TRAK-BASE01]

 TASK [debug] 
 
 ok: [TRAK-BASE01] => {
 "msg": [
 "\r",
 "Welcome to BASE\r",
 "   My configuration is up to date\r",
 "   Print settings are normal\r",
 "\r",
 "\r",
 "Username: sq\r",
 "Password: SoLong>\r",
 "BASE>H"
 ]
 }

 PLAY RECAP 
 
 TRAK-BASE01: ok=3changed=1unreachable=0   
  failed=0skipped=0rescued=0ignored=0

 How do I 

Re: [ansible-project] Identify most recent directory in a directory.

2022-12-01 Thread Vladimir Botka
Use Ansible module *find* and sort the directories by *ctime*. For
example, given the tree

shell> tree /tmp/test
/tmp/test
├── 2022-12-01_1701
├── 2022-12-01_1702
└── 2022-12-01_1703

Declare the variable

  last_dir: "{{ (out.files|sort(attribute='ctime')|last).path }}"

The tasks below

- find:
path: /tmp/test
file_type: directory
  register: out
- debug:
var: last_dir

give

  last_dir: /tmp/test/2022-12-01_1703

If you want to take look at the *ctime*

  path_ctime: "{{ out.files|json_query('[].[path, ctime]') }}"

give

  path_ctime:
- [/tmp/test/2022-12-01_1702, 1669938403.313556]
- [/tmp/test/2022-12-01_1701, 1669938401.2335565]
- [/tmp/test/2022-12-01_1703, 1669938405.0495553]

-- 
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/20221202011038.0ed02422%40gmail.com.


pgpuhZVpCLY4r.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Identify most recent directory in a directory.

2022-12-01 Thread Thanh Nguyen Duc
Is it the shell script also be triggered via ansible? If yes then you can 
register the path and work with it later. If not then do you know roughly when 
script be triggered then can just use shell command to find the directory with 
created date.

Sent from my iPhone

> On 2 Dec 2022, at 05:57, Jason Wood  wrote:
> 
> After performing a shell script, a new directory is created and I need to 
> work with that directory, but I don't know the name.
> 
> How can I get the name of the most recent directory created?
> 
> The name will be formatted like 2022-12-01_1702, so the directory I need will 
> be the last if sorted alphanumerically, if that helps.
> 
> I found resources for looking at files, but not directories. If it's 
> necessary to find this directory based on the creation date of its contents, 
> there are files located at [dirname]/Databases/Filename.xxx
> 
> Thanks!
> -- 
> 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/3b559b55-8658-4df0-b32b-a227def8ca40n%40googlegroups.com.

-- 
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/7E74CF9E-4D72-480F-805B-D1F6735E8F18%40gmail.com.


[ansible-project] Identify most recent directory in a directory.

2022-12-01 Thread Jason Wood
After performing a shell script, a new directory is created and I need to 
work with that directory, but I don't know the name.

How can I get the name of the most recent directory created?

The name will be formatted like 2022-12-01_1702, so the directory I need 
will be the last if sorted alphanumerically, if that helps.

I found resources for looking at files, but not directories. If it's 
necessary to find this directory based on the creation date of its 
contents, there are files located at [dirname]/Databases/Filename.xxx

Thanks!

-- 
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/3b559b55-8658-4df0-b32b-a227def8ca40n%40googlegroups.com.


Re: [ansible-project] Re: Ansible Roles - Concept

2022-12-01 Thread Robert Grießner
thx samuel, looks good. if there's some time i'll have a try. br, robert

samuel@gmail.com  schrieb am Mo., 28. Nov.
2022, 17:57:

> Hi RG,
>
> Here is a solution for that problem which I have used for a long time,
> maybe before ansible tags were available.
>
> tasks/main.yml:
>
> - name: include client
>   import_tasks: client.yml
>   when: run_nfs_client is defined
>
>
> - name: include server
>   import_tasks: server.yml
>   when: run_nfs_server is defined
>
> playbook.yml:
>
> ---
> - hosts: nfs_clients
>   become: true
>   roles:
> - {role: 'nfs_role', run_nfs_client: true}
>
> - hosts: nfs_servers
>   become: true
>   roles:
> - {role: 'nfs_role', run_nfs_server: true}
>
> ---
>
> Let's consider tags instead.
> You wrote "this doesn't work". What exactly happened?
> If you run your playbook with an ordinary call to ansible-playbook, it
> will follow the default behavior: "--tags all - run all tasks, ignore tags
> (default behavior)".  So, it will 'ignore tags'. If it's ignoring tags,
> whatever solution you tried to implement with tags won't take effect.
>
> Next, if you run this:
> ansible-playbook -t create_nfs_cmp
> It will execute on the cmp hosts. But it will run the whole nfs role
> (unless you have tagged specific tasks).
>
> A step towards a solution could be to add the tags in tasks/main.yml
> instead.
>
> tasks/main.yml:
>
> - name: include nfs server
>   import_tasks: install_cmp.yml
>   tags:
> - nfs_server_tag
>
> - name: include nfs clients
>   import_tasks: install_machines.yml
>   tags:
> - nfs_client_tag
>
> Then if you have a playbook clients.yml as follows:
>
> clients.yml:
>
> - hosts: nfs_clients
>   become: true
>   roles:
> - nfs_role
>
> and run it:
>
> ansible-playbook -t nfs_client_tag clients.yml
>
> or similarly create this,
>
> ansible-playbook -t nfs_server_tag servers.yml
>
> So, that should work. But how to join them all together in one big
> playbook without resorting to the trick I mentioned at the beginning?  Is
> that method still necessary?
>
> A confusion with tags is to distinguish between labeling tasks versus
> choosing which ones will be processed.  It's easy to get those two sides of
> the equation mixed up. In order to select which tags will get processed you
> have to run the ansible-playbook command with the -t flag.
>
> On Wednesday, November 23, 2022 at 6:19:57 AM UTC-7 RG wrote:
>
>> i'd like to migrate my playbooks into ansible roles. I started but a
>> basic question raises.
>> E.g.
>> I'd like to implement nfs in a bunch of of linux machines. on one machine
>> i've to configure the nfs-sharing and on the other machines I've to implemt
>> the link to the nfs-sourcing host.
>>
>> systemA - configure a share for other hosts
>> systemB,C,D - use the nfs-sharing from system A
>>
>> I tried to create a role called nfs where i have to configure a few tasks
>> on systemA and the other tasks on systemB,C,D
>> I've splitted the tasks into 2 vaious task files one for systemA and one
>> for systemB and both will be imported into main.yml in tasks.
>> ---
>> # tasks file for installing nfs
>> - import_tasks: install_cmp.yml
>> - import_tasks: install_machines.yml
>>
>> in the run.yml I tried to call the same role twice where I used tags to
>> call the plays for the cmp machine from install_cmp.yml and the tags in
>> install_machines for running the plays for the other machines. however this
>> doesn't work
>>
>> - hosts: cmp
>>   become: true
>>   tags:
>> - create_nfs_cmp
>> - config_exports_cmp
>> - exportfs_cmp
>> - symlink_cmp
>> - symlink_hostsini_cmp
>>   roles:
>> - nfs
>>
>> - hosts:
>> - hardware:!cmp
>> - vms
>>   become: true
>>   tags:
>> - create_nfs_machines
>> - mnt_nfs_machines
>>   roles:
>> - nfs
>>
>>
>> is my concept wrong, do I have to configure to roles one for setting up
>> nfs on cmp and one for implementing nfs on the machines or is it possible
>> to create just one role for installing nfs on with vaious tasks on various
>> machines?
>>
>> Thx
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/aVhsyBXc_vk/unsubscribe.
> To unsubscribe from this group and all its topics, 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/59451dbb-15ba-433f-97ee-7499057a39d8n%40googlegroups.com
> 
> .
>

-- 
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 

[ansible-project] Change VLAN using interactive playbook with prompt

2022-12-01 Thread Hossein Malakooti
 Hello Dear Fellows 
I am a newbie to Ansible I searched for in existing discussions but I 
couldn't find a clear answer , I was hoping you could help me find a write 
Config 

I am trying to write a playbook who *prompt* user for Interface ID and 
change the VLAN accordingly , My playbook works  without prompt but when I 
add prompt it throw a error 
it looks like I am not supposed to put *vars_promp* after config but I 
tried in different lines and non of them worked 

*Here Is My Inventory Yaml File:*
all:
   children: 
  switches:
 children:
ios:
 hosts:
  sw-1:
 ansible_host: 10.10.10.20
 vars:
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
ansible_become: yes
ansible_connection: network_cli
ansible_network_os: ios
ansible_become_method: enable
ansible_user: ncm
ansible_password: ncm

*And Here Is My Playbook*
---
 - name: Config VLAN
   hosts: switches

   tasks:
  - name: Configure Access
ios_l2_interfaces:
  config: 
* vars_prompt:*
 

*   - name: "Interface"  prompt: "Enter Interface Name"
  private: false*
  access:
  vlan: 7
  state: merged

here is the original playbook which actually works but with an static value 
for interface ID
---
 - name: Config VLAN
   hosts: switches 
   
   tasks:
  - name: Configure Access 
ios_l2_interfaces:
  config: 
- name: GigabitEthernet1/0/35
  access:
vlan: 7
  state: merged


*Thanks for you time in advance *

-- 
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/10eeda64-9aa6-4420-af1a-d6be42f9d294n%40googlegroups.com.


[ansible-project] Selectively running tasks but using static includes

2022-12-01 Thread Mark Faine
This is a terrible weakness in Ansible for me.   I don't want to choose 
between dynamic and static imports.  I want to be able to do both.

I want to be able to use features like --list-tasks and --list-tags but I 
also want to be able to selectively run tagged tasks within a role.  Has 
anyone come up with a workaround?

-- 
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/a5c0c98a-cb4a-4001-b3b6-8377b01b2be8n%40googlegroups.com.


Re: [ansible-project] Ansible Expect Prompt set to a variable in Host not working

2022-12-01 Thread Matt Martz
Generally speaking, you cannot set keys anywhere in ansible to a template,
this is simply just not allowed.

As such, there really isn't a mechanism for doing this.  Keys must be
hardcoded.

On Thu, Dec 1, 2022 at 3:15 AM phillip.from.oz 
wrote:

> Hi,
> I'm trying to set Ansible Expect prompt to a variable in host file.
>
> However this does not work.
>
> You can see that Ansible is not sending a response to the prompt.
> The prompt is defined as the contents of a variable declared in host file.
>
> Can someone see what is wrong?
>
> ===
> This is the host file:
> [trak]
> BASE prompt="BASE\>"
>
> This is the Ansible playbook:
> ---
> - name: Test a conversation
>   hosts: BASE
>   remote_user: root
>   gather_facts: false
>
>   tasks:
>   - name: Copy script converse.py
> copy: src=/home/converse.py
> dest=/home/converse.py
> remote_src=no
> mode=preserve
>   - name: Run test session
> expect:
>   echo: yes
>   chdir: /tmp
>   command: python3 /home/converse.py
>   timeout: "300"
>   responses:
> Username: sq
> Password: "MeMe"
> "{{hostvars[inventory_hostname].prompt}}": ["w
> ##Class(websys).test()","H"]
> register: command_output
>   - debug:
>   msg: "{{ command_output.stdout.split('\n') }}"
>
>
>
>
> This is the result:
> # ansible-playbook test-converse.yml
>
> PLAY [Test a conversation]
> 
>
> TASK [Copy script converse.py]
> 
> changed: [BASE]
>
> TASK [Run test session]
> ***
> fatal: [BASE]: FAILED! =>
>{"changed": true, "cmd": "python3 converse.py", "delta":
> "0:05:00.340507",
> "end": "2022-12-01 19:12:18.727066", "msg": "command
> exceeded timeout",
> "rc": null, "start": "2022-12-01 19:07:18.386559",
> "stdout": "\r\nWelcome to BASE\r\n   My configuration is
> up to date\r\n
>Print settings are normal\r\n\r\n\r\n
> Username: sq\r\n
> Password: MeMe\r\n
> BASE>",
> "stdout_lines": ["", "Welcome to BASE", "   My
> configuration is up to date",
> "   Print settings are normal", "", "",
> "Username: sq", "Password: MeMe", "BASE>"]}
>
> PLAY RECAP
> **
> BASE : ok=1changed=1unreachable=0failed=1skipped=0
>  rescued=0ignored=0
>
> --
> 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/e8b0cfe2-6704-45db-b87c-68da18ba4e94n%40googlegroups.com
> 
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v9ts_6KwDRWQgjW4wEknNNkwo_1WSSPFv4JdjER9_zftg%40mail.gmail.com.


Re: [ansible-project] Ansible Expect - Program under control has same prompt

2022-12-01 Thread Dick Visser
Hi

It now partly works because you made the items of a single dict key into a
list and by doing so also quoted the value with '#' in it.
But what I meant is to have the responses itself be a list, so you can have
duplicates. I think this would look like:

responses:
  - Username: sq
  - Password: "SoLong>"
  - BASE\>: "w ##Class(websys).test()"
  - BASE\>: "H"
  - BASE1>: "foo"
  - BASE1>: "bar"
  - BASE1>: "bz"
  - BASE2>: "fog"
  - BASE2>: "fbzhy33"
  - BASE1>: "bar"


etc



On Wed, 30 Nov 2022 at 21:55, phillip.from.oz 
wrote:

> Thanks. That did the trick.
>
> I changed
> BASE\>: w ##Class(websys).test()
> BASE\>: H
> to
> BASE\>: ["w ##Class(websys.PatchHistory).test()","H"]
>
> However, how do I code the list if I have this set of prompts:
> BASE1>
> BASE1>
> BASE1>
> BASE2>
> BASE2>
> BASE1>
> BASE1>
> On Wednesday, November 30, 2022 at 4:02:42 PM UTC+11 dnmv...@gmail.com
> wrote:
>
>> Your responses is now a dict which cannot have the same key more than
>> once. So the second BASE question isn't going to work.
>> Try turning it into a list.
>> See
>> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html#examples
>>
>>
>>
>>
>> On Wed, 30 Nov 2022 at 02:03, phillip.from.oz 
>> wrote:
>>
>>> Hi,
>>> I want to run a program on a remote server where after login, the
>>> program will ask for more input using the same prompt.
>>>
>>> This is the basic flow:
>>> Read Username
>>> Read Password
>>> Read commands <- these get echoed back
>>> until 'h' or 'H' is entered
>>>
>>> This is a sample run of the program
>>> BASE:/home# python3 converse2.py
>>> Welcome to BASE
>>>My configuration is up to date
>>>Print settings are normal
>>>  Username: sq
>>>  Password: SoLong>
>>> BASE>w abc
>>> w abc
>>> BASE>h
>>>
>>> I run the same program using Ansible Expect with this playbook:
>>> ---
>>> - name: Test a conversation
>>>hosts: BASE
>>>remote_user: root
>>>gather_facts: false
>>>tasks:
>>> - name: Copy script converse2.py
>>>   copy: src=/home/converse2.py
>>>  dest=/home/converse2.py
>>>  remote_src=no
>>>  mode=preserve
>>> - name: Run test session
>>>   expect:
>>>  echo: yes
>>>  chdir: /tmp
>>>  command: python3 /home/converse2.py
>>>  timeout: "300"
>>>  responses:
>>>  Username: sq
>>>  Password: "SoLong>"
>>>  BASE\>: w ##Class(websys).test()
>>>  BASE\>: H
>>>  register: command_output
>>> - debug:
>>>   msg: "{{ command_output.stdout.split('\n') }}"
>>>
>>> However Ansible Expect is not sending 'w ##Class(websys).test()' to the
>>> program
>>>
>>> This is the run:
>>> ansible-playbook /home/ansible_playbooks/test-converse2.yml
>>> [WARNING]: While constructing a mapping from
>>> /home/ansible_playbooks/test-converse2.yml, line 20, column 9, found a
>>> duplicate dict key (BASE\>). Using last defined value only.
>>>
>>> PLAY [Test a conversation]
>>> 
>>>
>>> TASK [Copy script converse2.py]
>>> ***
>>> ok: [TRAK-BASE01]
>>>
>>> TASK [Run test session]
>>> 
>>> changed: [TRAK-BASE01]
>>>
>>> TASK [debug]
>>> 
>>> ok: [TRAK-BASE01] => {
>>> "msg": [
>>> "\r",
>>> "Welcome to BASE\r",
>>> "   My configuration is up to date\r",
>>> "   Print settings are normal\r",
>>> "\r",
>>> "\r",
>>> "Username: sq\r",
>>> "Password: SoLong>\r",
>>> "BASE>H"
>>> ]
>>> }
>>>
>>> PLAY RECAP
>>> 
>>> TRAK-BASE01: ok=3changed=1unreachable=0
>>>  failed=0skipped=0rescued=0ignored=0
>>>
>>> How do I fix this?
>>>
>>> --
>>> 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-proje...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/38895202-0733-4df4-8d11-1c661128f3f7n%40googlegroups.com
>>> 

[ansible-project] Ansible Expect Prompt set to a variable in Host not working

2022-12-01 Thread phillip.from.oz
Hi,
I'm trying to set Ansible Expect prompt to a variable in host file.

However this does not work.

You can see that Ansible is not sending a response to the prompt.
The prompt is defined as the contents of a variable declared in host file.

Can someone see what is wrong?

===
This is the host file:
[trak]
BASE prompt="BASE\>"

This is the Ansible playbook:
---
- name: Test a conversation
  hosts: BASE
  remote_user: root
  gather_facts: false

  tasks:
  - name: Copy script converse.py
copy: src=/home/converse.py
dest=/home/converse.py
remote_src=no
mode=preserve
  - name: Run test session
expect:
  echo: yes
  chdir: /tmp
  command: python3 /home/converse.py
  timeout: "300"
  responses:
Username: sq
Password: "MeMe"
"{{hostvars[inventory_hostname].prompt}}": ["w 
##Class(websys).test()","H"]
register: command_output
  - debug:
  msg: "{{ command_output.stdout.split('\n') }}"




This is the result:
# ansible-playbook test-converse.yml

PLAY [Test a conversation] 


TASK [Copy script converse.py] 

changed: [BASE]

TASK [Run test session] 
***
fatal: [BASE]: FAILED! =>
   {"changed": true, "cmd": "python3 converse.py", "delta": 
"0:05:00.340507",
"end": "2022-12-01 19:12:18.727066", "msg": "command 
exceeded timeout", 
"rc": null, "start": "2022-12-01 19:07:18.386559",
"stdout": "\r\nWelcome to BASE\r\n   My configuration is up 
to date\r\n
   Print settings are normal\r\n\r\n\r\n
Username: sq\r\n
Password: MeMe\r\n
BASE>",
"stdout_lines": ["", "Welcome to BASE", "   My 
configuration is up to date",
"   Print settings are normal", "", "",
"Username: sq", "Password: MeMe", "BASE>"]}

PLAY RECAP 
**
BASE : ok=1changed=1unreachable=0failed=1skipped=0   
 rescued=0ignored=0

-- 
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/e8b0cfe2-6704-45db-b87c-68da18ba4e94n%40googlegroups.com.


[ansible-project] How to Downgrade RHSA Security Patch with Playbook

2022-12-01 Thread Fabiuscom
 Hi, after install a RHSA security patch, I want to downgrade it with an 
ansible's playbook. How to do this? Because I know that yum can downgrade 
package with the package's name or history ID, but if i want downgrade 
without know ID or package that RHSA have installed? Thanks 

-- 
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/4392fe00-4959-40d4-9243-c0d8271baa02n%40googlegroups.com.