• How to run thread using expect

    From Luis Mendes@luisXXXlupe@gmail.com to comp.lang.tcl on Fri Sep 19 11:34:47 2025
    From Newsgroup: comp.lang.tcl

    Hi,

    I have a working script that creates a thread to execute an ansible
    command.
    Up until now, the ansible needed a password for ssh, which was provided
    by sshpass -p mypass to the ansible script, like:

    sshpass -p mypass ansible-playbook -b -i inv -e hosts=somehost* playbooks/ dosomething.yml -k


    Now, there's also a vault password that needs to be typed in, but since
    this framework is running automatically unattended, it needs to be sent
    to the executing thread.

    To keep changes to a minimal, I tried to provide two sshpass commands and
    also two passwords in the same command, but was not successful.

    So, I could replace the sshpass concept with Expect.

    ====
    The skeleton of what I have:

    set tid [thread::create -preserved $init_script]

    set init_script {
    ...
    runAnsible
    ...
    }


    proc runAnsible {exec_id ansible} {
    set run_${exec_id} [Parse new $exec_id $ansible $username $debug1]
    vwait :exit_flag
    }

    oo::class create Parse {
    variable ...
    constructor {ex_id ansible_comm username {dbg1 0}}
    set chan_ans [open |[list {*}$ansible_comm] r]
    chan configure $chan_ans -blocking 0 -buffering line
    chan event $chan_ans readable [list [self object] parseLine]
    ...
    ====


    I have two questions.

    1. Can I pass an entire Expect script that includes the previous ansible command (as $ansible_comm) to the 'set chan_ans [open |[list {*}
    $ansible_comm] r] line?
    Does it work with Expect that is not prepared AFAIT to threaded code?

    2. Is there any other better/simpler way to do this?


    Thanks in advance,

    Luis
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Colin Macleod@user7@newsgrouper.org.invalid to comp.lang.tcl on Fri Sep 19 12:38:09 2025
    From Newsgroup: comp.lang.tcl

    Luis Mendes <luisXXXlupe@gmail.com> posted:

    I have a working script that creates a thread to execute an ansible
    command.

    Unless it's been fixed recently, I don't think Expect is compatible
    with multithreaded code.
    --
    Colin Macleod ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://cmacleod.me.uk

    FEED FEED FEED FEED FEED FEED FEED FEED
    GAZA GAZA GAZA GAZA GAZA GAZA GAZA GAZA
    NOW! NOW! NOW! NOW! NOW! NOW! NOW! NOW!
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Christian Gollwitzer@auriocus@gmx.de to comp.lang.tcl on Fri Sep 19 18:42:17 2025
    From Newsgroup: comp.lang.tcl

    Am 19.09.25 um 13:34 schrieb Luis Mendes:
    I have a working script that creates a thread to execute an ansible
    command.
    Up until now, the ansible needed a password for ssh, which was provided
    by sshpass -p mypass to the ansible script, like:

    sshpass -p mypass ansible-playbook -b -i inv -e hosts=somehost* playbooks/ dosomething.yml -k


    and why do you not use SSH keys for this?

    Christian

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Luis Mendes@luisXXXlupe@gmail.com to comp.lang.tcl on Fri Sep 19 20:30:59 2025
    From Newsgroup: comp.lang.tcl

    On Fri, 19 Sep 2025 18:42:17 +0200, Christian Gollwitzer wrote:

    Am 19.09.25 um 13:34 schrieb Luis Mendes:
    I have a working script that creates a thread to execute an ansible
    command.
    Up until now, the ansible needed a password for ssh, which was provided
    by sshpass -p mypass to the ansible script, like:

    sshpass -p mypass ansible-playbook -b -i inv -e hosts=somehost*
    playbooks/
    dosomething.yml -k


    and why do you not use SSH keys for this?

    Christian

    Cannot Christian, thank you.
    --- Synchronet 3.21a-Linux NewsLink 1.2