Running commands as sudo

39 views
Skip to first unread message

lask001

unread,
Jun 28, 2017, 4:49:28 AM6/28/17
to Ansible Project
I haven't been using ansible that long, but so far I'm really liking it. I'm running into an issue though that I'm hoping someone will be able to shed some light on.

I have an account, foo on the server I want to run my playbook against. I'm trying to install an rpm. I do not have permissions to become root on said server with account foo. I do however, have the ability to install an rpm if I run the command as "sudo yum install ..."

I've tried all sorts of things and have had pretty much zero luck:

My playbook is pretty basic for this test run:

    ---
    - name: Test
      hosts: servers
      remote_user: food
      become: true
      become_user: foo
      become_method: sudo
      roles:
      - jdk

My role is has one task:

    - name: Install jdk
      yum:
        name: /tmp/jdk.rpm
        state: present

My inventory file is about as basic as you can get:

    [servers]
    host1

My ansible.cfg is as follows:

    [defaults]
    callback_whitelist = profile_tasks
    host_key_checking = False
    log_path = /etc/ansible/ansible.log
    #ask_sudo_pass = True
    
    [ssh_connection]
    ssh_args=-o ForwardAgent = yes
    pipelining = True

The errors I'm getting are along the lines of:

    fatal: [myserver]: FAILED! => {"changed": true, "failed": true, "msg": "Repo rhel-7-server-optional-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/*******************-key.pem\nRepo rhel-7-server-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/*******************-key.pem\nYou need to be root to perform this command.\n", "rc": 1, "results": ["Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-\n              : manager\n"]}

I've tried a ton of different iterations of the settings above with zero luck. Does anyone have any ideas on what I can do to get this to work? I know I could run everything as a shell script... but at that point it's hardly even ansible anymore. Thanks
Reply all
Reply to author
Forward
0 new messages