install a package in linux using ansible and y/n option

1,653 views
Skip to first unread message

sharan kumar

unread,
Feb 9, 2022, 7:04:54 AM2/9/22
to rundeck-discuss
I am trying to install a package in linux using yum .. but it is failing as  it is asking for a y/n option.

Any suggestions how to give yes/no option 


---
- hosts: dbserver
  become: yes
  vars_prompt:
    - name: input_an_option
      prompt: "Is this ok [y/d/N]"
  tasks:
  - debug:
      msg: option selected is {{ input_an_option }}
  - name: Install mysql
    command: yum -y install mysql-community-server
[ansible@node1 udemy_ansible]$ ansible-playbook playbooks/database.yaml
Is this ok [y/d/N]:

PLAY [dbserver] ********************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************

ok: [node5.example.com]

TASK [debug] ***********************************************************************************************************************************************************
ok: [node5.example.com] => {
    "msg": "option selected is "
}

TASK [Install mysql] ***************************************************************************************************************************************************
[WARNING]: Consider using the yum module rather than running 'yum'.  If you need to use command because yum is insufficient you can add 'warn: false' to this command
task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
fatal: [node5.example.com]: FAILED! => {"changed": true, "cmd": ["yum", "-y", "install", "mysql-community-server"], "delta": "0:00:03.873598", "end": "2022-02-09 02:47:52.812896", "msg": "non-zero return code", "rc": 1, "start": "2022-02-09 02:47:48.939298", "stderr": "warning: /var/cache/yum/x86_64/7Server/mysql80-community/packages/mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY\n\n\nThe GPG keys listed for the \"MySQL 8.0 Community Server\" repository are already installed but they are not correct for this package.\nCheck that the correct key URLs are configured for this repository.\n\n\n Failing package is: mysql-community-client-plugins-8.0.28-1.el7.x86_64\n GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql", "stderr_lines": ["warning: /var/cache/yum/x86_64/7Server/mysql80-community/packages/mysql-community-client-plugins-8.0.28-1.

Xavier Humbert

unread,
Feb 9, 2022, 8:02:03 AM2/9/22
to rundeck...@googlegroups.com, sharan kumar

Hi Sharan,


You'd better use a syntax like this :

- name: "install  package MySQL"
  yum:
    name: "mysql-community-server"
    state: "present"
  become: yes

HTH,

Xavier

Le 2/9/22 12:34, sharan kumar a écrit :
--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/fe57650f-d3be-4d9f-b0fd-df73b9ca828dn%40googlegroups.com.
-- 
Xavier Humbert
CRT Supervision et Exploitation de Niveau 1
Rectorat de Nancy-Metz
03 83 86 27 39
OpenPGP_0x90B78A89BCC49C10.asc
OpenPGP_signature

sharan kumar

unread,
Feb 10, 2022, 10:33:07 AM2/10/22
to rundeck-discuss
Hi Xavier,

Thanks for your time.

Have tried your suggestion but it is  failing as below .

rl-podlators                 noarch 2.5.1-3.el7      rhel7             112 k\n perl-threads                   x86_64 1.87-4.el7       rhel7              49 k\n perl-threads-shared            x86_64 1.43-6.el7       rhel7              39 k\n\nTransaction Summary\n================================================================================\nInstall  3 Packages (+32 Dependent packages)\n\nTotal size: 530 M\nTotal download size: 12 M\nDownloading packages:\n--------------------------------------------------------------------------------\nTotal                                               50 MB/s |  12 MB  00:00     \nRetrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql\n"

I did try to install the package manually and it is asking  Is this ok [y/d/N]: , so is there a way in ansible where we can update the y/n option during  run-time or in the playbook to run it without failing.

[ansible@node5 ~]$ sudo yum install mysql-community-server
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You c
Transaction Summary
========================================================================================================================================================================
Install  3 Packages (+32 Dependent packages)

Total size: 530 M
Total download size: 12 M
Is this ok [y/d/N]:

rac...@rundeck.com

unread,
Feb 10, 2022, 10:58:09 AM2/10/22
to rundeck-discuss
Hi Sharan,

If you want to "answer" interactive commands in Rundeck, a good way is to use expect tool, take a look at this answer.

Greetings.

sharan kumar

unread,
Feb 10, 2022, 1:47:07 PM2/10/22
to rundeck-discuss

Hi Rundeck, Thanks for your time.

Have tried it on rhel7.6 but its failing with below error, Will check it on rhel8 server and keep this thread posted.


---
- hosts: dbserver
  become: yes
  tasks:
  - name: install mysql package
    expect:
      command: yum install mysql-community-server
      responses:
        'Is this ok [y/d/N]:' : 'y'
      echo: yes


fatal: [node5.example.com]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "chdir": null,
            "command": "yum install mysql-community-server",
            "creates": null,
            "echo": true,
            "removes": null,
            "responses": {
                "Is this ok [y/d/N]:": "y"
            },
            "timeout": 30
        }
    },
    "msg": "Insufficient version of pexpect installed (2.3), this module requires pexpect>=3.3. Error was 'module' object has no attribute 'runu'"

sharan kumar

unread,
Feb 11, 2022, 6:53:39 AM2/11/22
to rundeck-discuss
Hi rundeck,

Have modified few details in the playbook and was able to install the package, Thanks rundeck for your suggestion.

have used timeout as 120 second as it was taking time to install mysql-community-server.

---
- hosts: qa
  become: yes
  vars_prompt:
  - name: package_selection
    prompt: name of package ?
    private: no
  tasks:
  - name: installing {{ package_selection }}
    expect:
      command: yum install {{ package_selection }}
      responses:
        'Is this ok \[y/N\]:' : 'y'
      echo: yes
      timeout: 120
[ansible@contorl ~]$

name of package ?: httpd

PLAY [qa] **************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.]

TASK [installing httpd] *************************************************************************************************************************************************
skipping: [172.]

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

[contorl ~]$

Thank you all once again.

Reply all
Reply to author
Forward
0 new messages